Chenille33
Chenille33

Reputation: 191

Transform docker-compose.yml to docker run

I'm new in docker and I don't understand how to transform this docker-compose.yml:

version: '3'
services:
  php:
    build: .
    volumes:
      - "./:/var/www/html:ro"
      - "./:/var/log/php"

into a simple docker command in one line (if possible).

I've tried this:

docker build -t mstp2html --mount source=./,target=/var/www/html,ro --mount source=./,target=/var/log/php -f- .

and this:

docker run --name mstp2html --mount source=./,target=/var/www/html,ro --mount source=./,target=/var/log/php ./Dockerfile

but they don't work. What am I missing?

Upvotes: 1

Views: 3214

Answers (1)

Marcos Parreiras
Marcos Parreiras

Reputation: 388

You are mixing two concepts:

  • build: the stage in which the docker image is created, but it does not have relation on how it will run
  • run: the stage in which you run a docker container based on an existing docker image. In this stage, you can define options such as volumes.

In order for your example to work, you would need to split that into two stages:

  1. Build the docker image:
docker build -t mstp2html_image .
  1. Run a container from the image and mount the volumes you want to:
docker run --name mstp2html --mount type=bind,source="$(pwd)",target=/var/www/html,ro --mount type=bind,source="$(pwd)",target=/var/log/php mstp2html_image

Upvotes: 2

Related Questions