smebberson/alpine-nginx
Alpine Linux, s6 process management running nginx. Super small and super fast.
100K+
A Docker image for running nginx, based on Alpine Linux. This image belongs to a suite of images documented here.
This image features:
3.0.0
, latest
(Dockerfile)2.1.1
(Dockerfile)2.1.0
(Dockerfile)2.0.0
(Dockerfile)1.0.0
(Dockerfile)See VERSIONS.md for image contents.
To use this image include FROM smebberson/alpine-nginx
at the top of your Dockerfile
, or simply docker run -p 80:80 -p 443:443 --name nginx smebberson/alpine-nginx
.
Nginx logs (access and error logs) aren't automatically streamed to stdout
and stderr
. To review the logs, you can do one of two things:
Run the following in another terminal window:
docker exec -i nginx tail -f /var/log/nginx/access.log -f /var/log/nginx/error.log
or, in your Dockerfile
symlink the Nginx logs to stdout
and stderr
:
RUN ln -sf /dev/stdout /var/log/nginx/access.log && \
ln -sf /dev/stderr /var/log/nginx/error.log
This container comes setup as follows:
To alter the HTML content that nginx serves up (add your website files), add the following to your Dockerfile:
ADD /path/to/content /usr/html/
index.html is the default, but that's easily changed (see below).
A basic nginx configuration is supplied with this image. But it's easy to overwrite:
nginx.conf
.Dockerfile
, make sure your nginx.conf
file is copied to /etc/nginx/nginx.conf
.Make sure you start nginx without daemon mode, by including daemon off;
in your nginx configuration, otherwise the container will constantly exit right after nginx starts.
If you're running another process to keep track of something down-stream (for example, automatically updating nginx proxy settings when a down-stream application server (nodejs, php, etc) restarts) execute the command s6-svc -h /var/run/s6/services/nginx
to send a SIGHUP
to nginx and have it reload its configuration, launch new worker process(es) using this new configuration, while gracefully shutting down the old worker processes.
By default, if nginx crashes, the container will stop. This has been configured within root/etc/services.d/nginx/finish
. This is so the host machine can handle any issues, and automatically restart it (the docker way, docker run --autorestart
).
If you don't want this to happen, simply replace the root/etc/services.d/nginx/finish
with a different file in your image. I like to ln -s /bin/true /root/etc/services.d/nginx/finish
in those instances in which you don't need a finish script and want to have the service restarted by s6.
If you need to, you can run a setup script before starting nginx. During your Dockerfile build process, copy across a file to /etc/services.d/nginx/run
with the following (or customise it as required):
#!/usr/bin/with-contenv sh
if [ -e ./setup ]; then
./setup
fi
# Start nginx.
nginx -g "daemon off;"
An example of using this image can be found in examples/user-nginx.
docker pull smebberson/alpine-nginx