Well I have set up an alpine linux docker container with nginx on it

(apk add nginx)

Now I am trying to run nginx. With the simple command nginx This returns the following error:

nginx: [emerg] open() "/run/nginx/nginx.pid" failed (2: No such file or directory)

What is causing this? - Even as root I do not have permission to open /run/ so I can't really check things out. My nginx.conf is:

events {
    worker_connections 768;
    # multi_accept on;

http {

    # Basic Settings

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    #include /etc/nginx/mime.types;
    #default_type application/octet-stream;

    # SSL Settings

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    # Logging Settings

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    # Gzip Settings

    gzip on;
    gzip_disable "msie6";

    # Virtual Host Configs

    #include /etc/nginx/conf.d/*.conf;
    #include /etc/nginx/sites-enabled/*;

Sure no server is included, but I expect it to be able to run and just never serve anything. - But even if I do enable the inclusion (which redirects to the default html into page, which I have also copied into the docker) the same error occurs.


The /run/nginx directory does not exist on the latest alpine containers.

You can either create the directory or change the PID file location.

Create the directory in your Dockerfile:

RUN mkdir -p /run/nginx

Or change the location of the PID file:

nginx -g 'pid /tmp/nginx.pid;'
  • nginx: [emerg] unexpected end of parameter, expecting ";" in command line You actually need to put a ";" at the end of the parameter nginx -g 'pid /tmp/nginx.pid;'
    – Sylver
    Oct 18 '19 at 13:14

Alpine linux does not have run/nginx/nginx.pid. Try add this on the top nginx.conf file.

pid /run/nginx.pid;

  • Can you elaborate on this a little more?
    – Toto
    Jul 6 '18 at 10:28
  • I have edited my answer above. There is a change in path. Jul 6 '18 at 10:45

There is no real need to create your own nginx docker container from the alpine base image when there is an official, Alpine nginx docker image on Docker Hub.

Here is a Dockerfile of nginx upstream docker image.

To pull it directly from Docker hub, use:

$ docker pull nginx:alpine

You can modify its Dockerfile with your custom variables and build your own image.

$ docker build -t nginx-alpine
  • You can't assume that "there is no real need". In my case, I have to use a custom nginx build with optional modules. That is a real need. Jul 12 '19 at 2:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.