docker-nginx icon indicating copy to clipboard operation
docker-nginx copied to clipboard

mkdir() "/var/cache/nginx/client_temp" failed (13: Permission denied)

Open lbopp42 opened this issue 4 years ago • 20 comments

Hello, I'm using the image nginx:alpine and sometime for the first docker-compose up -d I got this error spammed in logs and container restarting:

mkdir() "/var/cache/nginx/client_temp" failed (13: Permission denied)

If I docker-compose up -d again my container will be fixed but why ?

Best regards, Lucas BOPP

lbopp42 avatar Mar 19 '21 09:03 lbopp42

Hi @lbopp42, can you show the full configuration you're using? All the docker-compose configs, and nginx ones.

Thanks,

thresheek avatar Mar 19 '21 09:03 thresheek

Hi thanks for your time. I'm using the default conf of nginx:alpine and this is a part of docker-compose

  my_service: (edit)
    cap_add:
    - CAP_CHOWN
    - CAP_NET_BIND_SERVICE
    - CAP_SETGID
    - CAP_SETUID
    cap_drop:
    - ALL
    depends_on:
    - app_back (edit)
    env_file:
    - .env
    image: myimage_name (edit)
    labels:
       some_labels_for_traefik (edit)
    networks:
    - default
    - traefik
    restart: always

Do this help you ?

lbopp42 avatar Mar 19 '21 10:03 lbopp42

Not really, I cant reproduce with the following docker-compose.yml:

my_service:
  cap_add:
  - CAP_CHOWN
  - CAP_NET_BIND_SERVICE
  - CAP_SETGID
  - CAP_SETUID
  cap_drop:
  - ALL
  image: nginx:alpine
  restart: always

Are there any changes you're doing to nginx:alpine image? I notice you have myimage_name instead.

thresheek avatar Mar 19 '21 10:03 thresheek

this is my Dockerfile:

FROM nginx:alpine
COPY application /usr/share/nginx/html
COPY ./entrypoint.sh /
CMD ./entrypoint.sh
EXPOSE 80

entrypoint.sh get only some sed (in my source) and run nginx -g 'daemon off;'

I can't reproduce it all time. That's strange and if I docker-compose up -d --force-recreate without any change, that work.

lbopp42 avatar Mar 19 '21 10:03 lbopp42

Is that on a local Linux machine, or is that via some virtualbox or docker for mac or docker for windows, or similar setup where things are heavily virtualized and, maybe, volumes are used?

No idea otherwise, this seems like something unrelated to the image itself.

thresheek avatar Mar 19 '21 11:03 thresheek

It's on an ubuntu server 16.04 and on 18.04 too. Il will let this issue open if someone have the same

lbopp42 avatar Mar 19 '21 13:03 lbopp42

Any apparmor or similar permission denied errors in dmesg or messages or other system logs?

thresheek avatar Mar 19 '21 14:03 thresheek

I have the same problem on Azure AKS. In this case I don't know what to change.

P.S. There is also permission problem with nginx.pid, but I change path to /tmp/nginx.pid

kfkawalec avatar Mar 19 '21 21:03 kfkawalec

@kfkawalec Are you launching the containers as a specific user? What is the setup for a container in your case?

thresheek avatar Mar 26 '21 10:03 thresheek

yes, I'm run this as non root user

kfkawalec avatar Mar 26 '21 10:03 kfkawalec

@kfkawalec then https://github.com/nginxinc/docker-nginx-unprivileged might be relevant to your interests :-)

thresheek avatar Mar 26 '21 10:03 thresheek

I have the same problem, deploying container to Openshift4 the startup will fail with:

mkdir() "/var/cache/nginx/client_temp" failed (13: Permission denied)

The docker-nginx-unprivileged works but is too big (150mb vs 58mb)

pancudaniel7 avatar Jun 27 '21 17:06 pancudaniel7

@pancudaniel7 you need to apply the same configuration fixes as in docker-nginx-unprivileged if you'd like to use this repo images on openshift. they're not compatible as is.

thresheek avatar Jul 02 '21 08:07 thresheek

Thank you @thresheek I've fixed the problem by running the container with nginx user. This also allow you to increase security by using specific permissions on that nginx user.

Openshift in my case runs with a default user that did not have rights and thats why the nginx container failed at startup.

pancudaniel7 avatar Jul 02 '21 12:07 pancudaniel7

go to https://hub.docker.com/_/nginx and find section "Running nginx as a non-root user" you need to change some paths in your config

namevic avatar Aug 30 '21 13:08 namevic

Can you show me the output of the following command cd /var/cache/nginx ls

my problem was solved by creating "client_temp" directory in /var/cache/nginx.

P.S: I am not using docker.

Majid-cloud avatar Nov 01 '21 11:11 Majid-cloud

FYI, i had the same if i run nginx with my host user id ie

nginx:
    user: $UID

bizmate avatar Jan 16 '22 05:01 bizmate

Is there a reason the unprivileged image cannot replace the default one (except the different port)?

orgads avatar Jun 11 '23 09:06 orgads

hi @Majid-cloud , if I create one directory then it ask for another directory and list keep going on. I have same problem with GKE cluster. If I go with unprivileged image then I face port binding error for port 80 Did anyone have any working solution?

dikshant-devops avatar Feb 27 '24 17:02 dikshant-devops