I have Dockerfile with myuser from nginx image and I want to mount logs on mounted location, I am using docker-compose to start the container. My requirement is to use non-root user only and no sudo.
My dockerfile with myuser, image tag I create is mynginx:v1
RUN addgroup mygroup
RUN adduser myuser --disabled-password
USER myuser
Non-Working docker compose with mynginx image with myuser
version: "2"
services:
nginx:
container_name: nginx
image: mynginx:v1
ports:
- "8888:80"
volumes:
- ./log/nginx:/var/log/nginx
Although directory get mounted, nginx log files access.log and error.log are not seen on host machine.
Docker logs gives below:
nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)
2021/04/09 12:46:08 [warn] 1#1: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:2
2021/04/09 12:46:08 [emerg] 1#1: mkdir() "/var/cache/nginx/client_temp" failed (13: Permission denied)
However If I do the same with official nginx image which runs as root user, things work correctly.
Working docker compose with official nginx image with root user
version: "2"
services:
nginx:
container_name: nginx
image: nginx
ports:
- "8888:80"
volumes:
- ./log/nginx:/var/log/nginx
Tried to look at various options but no luck so far.