2

I am trying to use nginx on my docker server, but when creating a volume pointing to /etc/nginx, nginx fails to launch and the volume ends up being empty.

Here is my docker-compose.yml:

version: '3'

services:

  nginx:
    image: nginx:1.15-alpine
    container_name: nginx-1
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./www:/var/www
      - ./container/nginx/conf:/etc/nginx

Upon running docker-compose up...

nginx-1        | nginx: [emerg] open() "/etc/nginx/nginx.conf" failed (2: No such file or directory)
nginx-1 exited with code 1

If I remove - ./container/nginx/conf:/etc/nginx from the docker-compose.yml, it boots up fine, but uses the default config.

This happens on both nginx:1.15-alpine and nginx:latest.

What am I doing wrong? Thanks for your answers in advance!

1
  • I am in the same situation and it is about trying to copy the entire folder.
    – Manolait
    Commented Sep 9, 2019 at 11:54

1 Answer 1

0

I managed to find a workaround.

I ran the a temporary container with a different directory assigned to the volume, then copied the contents from /etc/nginx within the container to the volume.

docker run -v ~/container/nginx/conf:/temp nginx:latest nginx-temp cp -r /etc/nginx /tmp

CTRL+C'd afterward, and the volume has the correct contents now. A kind of cumbersome, and probably far from best practice solution, but it works.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .