shearichard
shearichard

Reputation: 8362

How do I emulate this "docker run" command in a docker-compose.yml?

docker run command

I'm using the following command to launch a Docker container.

    docker run -it --rm -d -p 8080:80 \
        -v ~/dev/react-using-camera/.nginx-conf-for-container/conf.d:/etc/nginx/conf.d \
        -v ~/dev/nginx-test-area:/usr/share/nginx/html/ \
        --name web \
        nginx:stable-alpine

The command works satisfactorily:

Using 'docker-compose up'

I would like to achieve the same effect by using docker-compose up and so I have written the following docker-compose.yml

version: "3.7"
services:
  ingress:
    image: nginx:stable-alpine
    container_name: docker-compose-test-0
    networks:
      - gateway
    ports:
      - '8080:80'
    restart: unless-stopped
    volumes:
      - /home/glaucon/dev/react-using-camera/.nginx-conf-for-container/conf.d:/etc/nginx/conf.d
      - /home/glaucon/dev/nginx-test-area:/usr/share/nginx/html/ \

networks:
  gateway: {}

When I use that file with docker-compose up :

Question

How may I emulate the use of the '-v' arguments in my docker run command in the context of docker-compose up ?

Upvotes: 0

Views: 109

Answers (1)

Turing85
Turing85

Reputation: 20185

The second volume-definition has a trailing backslash:

services:
  ingress:
    ...
    volumes:
      ...
      - /home/glaucon/dev/nginx-test-area:/usr/share/nginx/html/ \

If we remove the trailing backslash:

services:
  ingress:
    ...
    volumes:
      ...
      - /home/glaucon/dev/nginx-test-area:/usr/share/nginx/html/

it should work as expected.

Upvotes: 1

Related Questions