nginx fails to launch in docker when creating volume for /etc/nginx, volume ends up being empty

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!

lizardguy

Posted 2019-09-05T17:09:59.410

Reputation: 21

I am in the same situation and it is about trying to copy the entire folder. – Manolait – 2019-09-09T11:54:13.847

Answers

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.

lizardguy

Posted 2019-09-05T17:09:59.410

Reputation: 21