Home > Mobile >  Transform docker-compose.yml to docker run
Transform docker-compose.yml to docker run

Time:04-15

I'm newer 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 don't work. What I've missing ?

CodePudding user response:

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
  • Related