Docker Community Forums

Share and learn in the Docker community.

Can mount nginx configuration volume

Hello,

I have some docker container running in a little server.

I have problems with nginx container, I can not mount “/etc/nginx” container folder to my host. This is my configuration:

$ cat docker-compose.yml 
version: '3'
services:
  nginx:
    image: nginx:latest
    container_name: nginx
    volumes:
      - $PWD/docker_data/nginx/conf:/etc/nginx
    ports:
      - 80:80
      - 443:443
    restart: always

This is the output:

2020/04/05 15:19:58 [emerg] 1#1: open() "/etc/nginx/nginx.conf" failed (2: No such file or directory),
nginx: [emerg] open() "/etc/nginx/nginx.conf" failed (2: No such file or directory),
2020/04/05 15:20:00 [emerg] 1#1: open() "/etc/nginx/nginx.conf" failed (2: No such file or directory),
nginx: [emerg] open() "/etc/nginx/nginx.conf" failed (2: No such file or directory),

And this the host folder permssions:

$ ls -lha docker_data/nginx/
total 12K
drwxr-xr-x  3 root root 4,0K abr  5 17:19 .
drwxr-xr-x 11 root root 4,0K abr  5 17:19 ..
drwxr-xr-x  2 root root 4,0K abr  5 17:19 conf

I try to change the to alpine image (nginx:alpine), but same error.

The only way to get it working is to declare a volume for the configuration:

version: '3'
services:
  nginx:
    image: nginx:latest
    container_name: nginx
    volumes:
      - nginx-config:/etc/nginx
    ports:
      - 80:80
      - 443:443
    restart: always

volumes:
  nginx-config:

But I want to get the configuration files in my home folder. It works well for other containers I have in the same host.

Am I missing any special configuration?

Kind regards.

Let me quote the relevant detail from the Dockerhub description:

User and group id

Since 1.17.0, both alpine- and debian-based images variants use the same user and group ids to drop the privileges for worker processes:

$ id
uid=101(nginx) gid=101(nginx) groups=101(nginx)

Either you change the permission mask for $PWD/docker_data/nginx/conf to 777, or make UID/GID 101 the owner of the folder. Since your seem to use the docker cli / docker-compose as root, your should still be able to access the data inide the folder.

Hello,

I try to chmod and chown but I have same error logs:

# chmod 777 docker_data/nginx/config/
# chown 101:101 docker_data/nginx/config/

2020/04/08 13:08:46 [emerg] 1#1: open() "/etc/nginx/nginx.conf" failed (2: No such file or directory)
nginx: [emerg] open() "/etc/nginx/nginx.conf" failed (2: No such file or directory)

I am not running as root, I configure and run docker with a normal user:

$ id
uid=1000(lazkano) gid=1000(lazkano) grupos=1000(lazkano),24(cdrom),25(floppy),29(audio),30(dip),44(video),46(plugdev),109(netdev),998(docker)

Kind regards.

Seems like I should have mentioned that that the permission needs to be applied to the files inside the folder as well. Either chmod or chown are sufficient…