Sign inSign up

behance/docker-nginx

By behance

Updated about 4 years ago

Provides base OS, patches and stable nginx for quick and easy spinup

Image
2

1M+

behance/docker-nginx repository overview

docker-nginx

https://hub.docker.com/r/behance/docker-nginx/tags/

Provides base OS, patches and stable nginx for quick and easy spinup.

  • Ubuntu used by default
  • Alpine builds available tagged as -alpine
  • Centos builds available tagged as -centos

S6 process supervisor is used for only for zombie reaping (as PID 1), boot coordination, and termination signal translation

Goss is used for build-time testing.

See parent(s) docker-base for additional configuration

Expectations
  • Applications must copy their html/app into the /var/www/html folder
  • Any new script/file that needs to be added must be given proper permissions/ownership to the non root user through container/root/scripts/set_permissions.sh. This is to ensure that the image can be run under a non root user.
  • NOTE: Nginx is exposed and bound to an unprivileged port, 8080
Container Security

See parent configuration

HTTPS usage

To enable this container to serve HTTPS over its primary exposed port:

  • SERVER_ENABLE_HTTPS environment variable must be true
  • Certificates must be present in /etc/nginx/certs under the following names:
    • ca.crt
    • ca.key
  • Additionally, they must be marked read-only (0600)
Local development usage

To generate a self-signed certificate (won't work in most browsers):

openssl genrsa -out ca.key 2048
openssl req -new -key ca.key -out ca.csr -subj '/CN=localhost'
openssl x509 -req -days 365 -in ca.csr -signkey ca.key -out ca.crt

Run the image in background, bind external port (443), flag HTTPS enabled, mount certificate:

docker run \
  -d
  -p 443:8080 \
  -e SERVER_ENABLE_HTTPS=true \
  -v {directory-containing-ca.crt-and-ca.key}:/etc/nginx/certs:ro
  behance/docker-nginx

Test

curl -k -vvv https://{your-docker-machine-ip}
Environment Variables
VariableExampleDescription
SERVER_MAX_BODY_SIZESERVER_MAX_BODY_SIZE=4MAllows the downstream application to specify a non-default client_max_body_size configuration for the server-level directive in /etc/nginx/sites-available/default
SERVER_INDEXSERVER_INDEX index.html index.html index.phpChanges the default pages to hit for folder and web roots
SERVER_APP_NAMESERVER_APP_NAME='view'Gets appended to the default logging format
SERVER_GZIP_OPTIONSSERVER_GZIP_OPTIONS=1Allows default set of static content to be served gzipped
SERVER_SENDFILESERVER_SENDFILE=offAllows runtime to specify value of nginx's sendfile (default, on)
SERVER_ENABLE_HTTPSSERVER_ENABLE_HTTPS=trueEnable encrypted transmission using certificates
SERVER_KEEPALIVESERVER_KEEPALIVE=30Define HTTP 1.1's keepalive timeout
SERVER_WORKER_PROCESSESSERVER_WORKER_PROCESSES=4Set to the number of cores in the machine, or the number of cores allocated to container
SERVER_WORKER_CONNECTIONSSERVER_WORKER_CONNECTIONS=2048Sets up the number of connections for worker processes
SERVER_CLIENT_HEADER_BUFFER_SIZESERVER_CLIENT_HEADER_BUFFER_SIZE=16kdocs
SERVER_LARGE_CLIENT_HEADER_BUFFERSSERVER_LARGE_CLIENT_HEADER_BUFFERS=8 16kdocs
SERVER_CLIENT_BODY_BUFFER_SIZESERVER_CLIENT_BODY_BUFFER_SIZE=128kdocs
SERVER_LOG_MINIMALSERVER_LOG_MINIMAL=1Minimize the logging format, appropriate for development environments
S6_KILL_FINISH_MAXTIMES6_KILL_FINISH_MAXTIME=55000The maximum time (in ms) a script in /etc/cont-finish.d could take before sending a KILL signal to it. Take into account that this parameter will be used per each script execution, it's not a max time for the whole set of scripts. This value has a max of 65535 on Alpine variants.
S6_KILL_GRACETIMES6_KILL_GRACETIME=500Wait time (in ms) for S6 finish scripts before sending kill signal
Startup/Runtime Modification
  • Environment variables are used to drive nginx configuration at runtime
  • See here for more advanced options
Shutdown Behavior

Graceful shutdown is handled as part of the existing S6 termination process, using a /etc/cont-finish.d script. Nginx will attempt to drain active workers, while rejecting new connections. The drain timeout is controlled by S6_KILL_FINISH_MAXTIME, which corresponds to the length of time the supervisor will wait for the script to run during shutdown. This value defaults to 55s, which deliberately less than an downstream load balancers default max connection length (60s). Each upstream's timeout must be less than the downstream, for sanity and lack of timing precision.

Long-running processes (workers + crons)
Container Organization

Besides the instructions contained in the Dockerfile, the majority of this container's use is in configuration and process. The ./container/root repo directory is overlayed into a container during build. Adding additional files to the folders in there will be present in the final image.

Nginx is currently set up as an S6 service in /etc/services-available/nginx, during default environment conditions, it will symlink itself to be supervised under /etc/services.d/nginx. When running under worker entrypoint (worker.sh), it will not be S6's service.d folder to be supervised.

Tag summary

Content type

Image

Digest

sha256:ff86270ba

Size

46.2 MB

Last updated

about 4 years ago

docker pull behance/docker-nginx