I was watching this Larcon EU 2019 video and found that you shouldn’t be running your docker containers as the root user. You don’t want many processes to run as root because that’ll potentially give a malicious programmer (hacker) root access to your machine.
I simply added the user definition, user: "${UID}:${GID}", to my docker-compose.yml file and tried to run the service and it blew up with this error:
Nginx error : [emerg] mkdir() “/var/cache/nginx/client_temp” failed (13: Permission denied)
This error is caused because nginx doesn’t have permission to access this file anymore.
The solution at its face is simple, just change the files permissions via chown -R $UID:$GID /var/cache/nginx/client_temp
This solution won’t work if your nginx container isn’t running, which is what will happen if you bring down the container and then try to start it with the new user definition.
My Solution
I had to modify my Dockerfile and rebuild the image with the RUN instructions. First I added the following instruction to the Dockerfile giving the user file permissions. NOTE: $UID:$GID should be replaced with the user and group you want to use.
RUN chown -R $UID:$GID /var/cache/nginx/client_temp
That was it. This fixed my error and I was off to the races.
If you found this post helpful, please share on social media.
