Dockfile
FROM gliderlabs/alpine:latest
RUN apk-install bash nginx
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
docker run -ti --rm --name base -P dev-alpine
nginx: [emerg] open() "/run/nginx/nginx.pid" failed (2: No such file or directory)
I'm having the same problem, exact same error message:
nginx: [emerg] open() "/run/nginx/nginx.pid" failed (2: No such file or directory)
Tried moving the "daemon off;" directive into the nginx.conf file as well, no change. Reproduced the same issue by running the container in interactive mode and manually running
nginx
and
nginx -g "daemon off;"
Docker version:
Docker version 1.10.3, build 20f81dd (running on Mac OSX)
Docker file:
FROM alpine
EXPOSE 80
RUN apk update \
&& apk add nginx
COPY nginx.conf /etc/nginx/nginx.conf
RUN mkdir -p /usr/share/nginx/www
COPY run.sh /usr/local/bin/run.sh
RUN chmod +x /usr/local/bin/run.sh
CMD ["/usr/local/bin/run.sh"]
the /usr/local/bin/run.sh script simply updates some HTML/JS assets and then executes 'nginx'
Full disclosure, very new to Alpine. Any help/guidance appreciated.
It looks like the build of nginx is using /run/nginx/nginx.pid for the default PID location. You can either create /run/nginx, or override the PID location, e.g. nginx -g 'pid /tmp/nginx.pid; daemon off;'
You can check configure options on nginx with -V - e.g.
bash-4.3# nginx -V
nginx version: nginx/1.10.1
built with OpenSSL 1.0.2h 3 May 2016
TLS SNI support enabled
configure arguments: --prefix=/var/lib/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --pid-path=/run/nginx/nginx.pid --lock-path=/run/nginx/nginx.lock --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-threads --with-stream --with-stream_ssl_module --with-http_slice_module --with-mail --with-mail_ssl_module --with-file-aio --with-http_v2_module --with-ipv6
Add following line to your Dockerfile:
RUN mkdir -p /run/nginx
The previous posted answers should be fine for solving this. I think it has enough visibility now that it can be closed and still searched for in the future. Though, maybe the nginx package should be creating this folder...
I know it is closed.. But just a question, how did you know that was necessary to create this directory to fix this issue? Just curious @svenvarkel
@klaygomes I don't know ... Perhaps it's 20+ years of experience ... :)
add the path:
mkdir -p /var/lib/nginx
mkdir -p /var/lib/nginx/tmp
how did say: @klaygomes.
Maybe a fresh pair of eyes can answer @klaygomes question how to get to the solution
RUN mkdir -p /run/nginx from /run/nginx/nginx.pid" failed (2: No such file or directory):
nginx -V it shows --pid-path=/run/nginx/nginx.pid this folder is indeed needed for process id storing
Most helpful comment
Add following line to your Dockerfile:
RUN mkdir -p /run/nginx