From 6a7315b9448315a82796967a08b4cdd6668f28cb Mon Sep 17 00:00:00 2001 From: Vaidas Jablonskis Date: Thu, 7 Jul 2016 16:58:30 +0100 Subject: [PATCH] initial commit --- Dockerfile | 8 ++++++++ README.md | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ bin/run.sh | 16 ++++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 Dockerfile create mode 100755 bin/run.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..412f66a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM alpine:3.4 + +RUN apk upgrade --no-cache +RUN apk add --no-cache nginx bash + +ADD bin/run.sh /run.sh + +ENTRYPOINT ["/run.sh"] diff --git a/README.md b/README.md index 443d02b..df50640 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,58 @@ # docker-nginx Minimal bare nginx docker image + + +### Configuration +There are two ways to pass nginx configuration. + +#### Config block via env variable +Read in a config block preserving new lines, etc. + +``` +read -r -d '' NGINX_CONFIG <<'EOF' +user nginx; +worker_processes auto; +error_log /dev/stderr error; + +events { + worker_connections 1024; +} + +http { + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 65; + types_hash_max_size 2048; + + include /etc/nginx/mime.types; + default_type application/octet-stream; + + server { + listen 80 default_server; + server_name _; + + location / { + return 200 "Everything is OK.\n"; + } + } +} +EOF +``` + +``` +export NGINX_CONFIG +docker run -ti --rm -e NGINX_CONFIG quay.io/ukhomeofficedigital/nginx:v0.0.1 +``` + +#### Config file via env variable +You can provide a config file inside a container instead. + +``` +docker run -ti --rm -e NGINX_CONFIG_FILE=/config/nginx.conf quay.io/ukhomeofficedigital/nginx:v0.0.1 +``` + + +### Extra Configs + +TODO diff --git a/bin/run.sh b/bin/run.sh new file mode 100755 index 0000000..a36f190 --- /dev/null +++ b/bin/run.sh @@ -0,0 +1,16 @@ +#!/bin/bash - + +set -o errexit + +mkdir -p /run/nginx + +# config file takes precedence +if [[ -f ${NGINX_CONFIG_FILE} ]]; then + nginx -g 'daemon off;' -c ${NGINX_CONFIG_FILE} +elif [[ -n ${NGINX_CONFIG} ]]; then + cp <(echo "${NGINX_CONFIG}") /etc/nginx/nginx.conf + nginx -g 'daemon off;' -c /etc/nginx/nginx.conf +else + echo "[error] please set NGINX_CONFIG_FILE or NGINX_CONFIG variable." + exit 1 +fi