Docker Community Forums

Share and learn in the Docker community.

Running NGINX with bind mount gives 403 forbidden

Hello, I’m trying to start a NGINX container with content hosted on my docker host.

To run it I’m doing:

docker run --name nginx -v /etc/samba/devbox/home-automation-ui:/usr/share/nginx/html -d -p 80:80 nginx

I’ve tried setting permissions on my docker host to 777, changing owner & group to nginx on my host, but when I point a browser to the container I keep getting a 403 forbidden.

If I shell into the container I get a permission denied when I try to cat the index.html file, even getting a directory listing generates a permission denied:

root@f45ddc5aa04a:/usr/share/nginx/html# ls -la
ls: cannot access ‘index.html’: Permission denied
total 0
drwxr-xr-x. 3 1003 1004 38 May 14 14:32 .
drwxr-xr-x. 3 root root 18 Apr 23 13:02 …
-??? ? ? ? ? ? index.html
drwxrwxrwx. 2 1003 1004 24 May 14 14:32 static

Any recommendations?

Thanks.

Please check first if the volume is present and the path’s are correct.
Volumes are not removed automatically if a container or image gets deleted. They are persistent.
If there is an old volume from a previous run still present, all stuff inside (including permissions) is also still there.

uhm, the nginx user/group on your host has high likely a different UID/GID than the nginx user/group inside the container. You have to change the owner of /etc/samba/devbox/home-automation-ui to the UID/GID from inside the container.

According the docs, the image uses following UID/GID:

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)