can't run nginx in alpine linux (docker)

Solution 1:

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;'

Solution 2:

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

pid /run/nginx.pid;