skip to Main Content

I’m installing nginx on top of an fpm-stretch based php docker image, copy some configuration and then run nginx -t in the Dockerfile.
That one fails with nginx: [emerg] open() "/tmp/nginx.pid" failed (13: Permission denied).

The configuration contains pid /tmp/nginx.pid;.

The Dockerfile is:

FROM php:7.3.11-fpm-stretch
run apt-get update && apt-get install -y nginx nginx-extras
COPY .system_conf/nginx/nginx.conf /etc/nginx/nginx.conf
COPY .system_conf/nginx/real-ip.conf /etc/nginx/real-ip.conf
COPY .system_conf/nginx/app.conf /etc/nginx/sites-enabled/default
run touch /tmp/nginx.pid
run chown -R www-data:www-data /tmp/nginx.pid /etc/nginx /var/www /usr/local/etc/php-fpm*
run ls -la /tmp/nginx.pid
run whoami
run nginx -t

And the build output is:

Step 6/10 : run touch /tmp/nginx.pid
 ---> Running in b78b8c25da6e
Removing intermediate container b78b8c25da6e
 ---> 0ca504a62dcc
Step 7/10 : run chown -R www-data:www-data /tmp/nginx.pid /etc/nginx /var/www /usr/local/etc/php-fpm*
 ---> Running in 6d0e3e6e0085
Removing intermediate container 6d0e3e6e0085
 ---> 5801bebe1238
Step 8/10 : run ls -la /tmp/nginx.pid
 ---> Running in 3779596a2bf9
-rw-r--r-- 1 www-data www-data 0 Aug  5 13:19 /tmp/nginx.pid
Removing intermediate container 3779596a2bf9
 ---> fa5fb9b67a43
Step 9/10 : run whoami
 ---> Running in 3c501d3ef8d0
root
Removing intermediate container 3c501d3ef8d0
 ---> f4c8d7c894a3
Step 10/10 : run nginx -t
 ---> Running in 91687a1ea4d2
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: [emerg] open() "/tmp/nginx.pid" failed (13: Permission denied)
nginx: configuration file /etc/nginx/nginx.conf test failed

And here comes the really weird thing:
This happens on my colleagues computer. On my computer, everything works fine as expected.
We are both running ubuntu (me 18.04, he 20.04) and the same docker versions (19.03).

Update 1:
I do chmod 777 /tmp/nginx.pid in the Dockerfile and I get the same error.

3

Answers


  1. Chosen as BEST ANSWER

    I needed to add a user directive to the Dockerfile:

    FROM php:7.3.11-fpm-stretch
    run apt-get update && apt-get install -y nginx nginx-extras
    COPY .system_conf/nginx/nginx.conf /etc/nginx/nginx.conf
    COPY .system_conf/nginx/real-ip.conf /etc/nginx/real-ip.conf
    COPY .system_conf/nginx/app.conf /etc/nginx/sites-enabled/default
    run touch /tmp/nginx.pid
    run chown -R www-data:www-data /tmp/nginx.pid /etc/nginx /var/www /usr/local /etc/php-fpm*
    run ls -la /tmp/nginx.pid
    user www-data
    run whoami
    run nginx -t
    

    I still don't know why it would work on an ubuntu 18.04 but not on 20.04, though.


  2. You might need to grant permissions to the file nginx.pid.

    Try this:

    FROM php:7.3.11-fpm-stretch
    RUN apt-get update && apt-get install -y nginx nginx-extras
    COPY .system_conf/nginx/nginx.conf /etc/nginx/nginx.conf
    COPY .system_conf/nginx/real-ip.conf /etc/nginx/real-ip.conf
    COPY .system_conf/nginx/app.conf /etc/nginx/sites-enabled/default
    RUN touch /tmp/nginx.pid
    RUN chmod 755 /tmp/nginx.pid
    RUN chown -R www-data:www-data /tmp/nginx.pid /etc/nginx /var/www /usr/local/etc/php-fpm*
    RUN ls -la /tmp/nginx.pid
    RUN whoami
    RUN nginx -t
    
    Login or Signup to reply.
  3. Two things to check:

    1. Pull the base image again, entirely possible they have done something to theirs: docker pull php:7.3.11-fpm-stretch

    2. Check for SELinux being enabled on the host or docker engine (docker info).

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search