Static NGINX build/binary in docker/container
10K+
| GitHub | DockerHub | Quay.io |
This is a static build/binary of NGINX.
Nginx (pronounced "engine-x") is an open source reverse proxy server for HTTP, HTTPS, SMTP, POP3, and IMAP protocols, as well as a load balancer, HTTP cache, and a web server (origin server). The nginx project started with a strong focus on high concurrency, high performance and low memory usage. It is licensed under the 2-clause BSD-like license.
These container images can be used almost in the same way as the official images nginx/nginx-unprivileged:mainline-alpine (nginx:mainline-alpine):
However, they do not contain a shell and therefore no envsubst (for templates).
Images: ghcr.io/tob1as/static-nginx, docker.io/tobi312/static-nginx, quay.io/tobi312/static-nginx
| Tags | Description | Registries | Platforms |
|---|---|---|---|
latest, <version>, privileged, <version>-privileged | privileged (root, port 80) | all | linux/amd64, linux/arm64, linux/arm/v7 |
latest-unprivileged, <version>-unprivileged, unprivileged | unprivileged (user 101, port 8080) | all | linux/amd64, linux/arm64, linux/arm/v7 |
<version>-privileged-<date>.<commit>, <version>-unprivileged-<date>.<commit> | unique (immutable) tag of a build | ghcr.io | linux/amd64, linux/arm64, linux/arm/v7 |
base-alpine, base-alpine-<version>, base-alpine-<version>-<date>.<commit> | base image (only /nginx, see "Use in own image"), built on Alpine (musl) | ghcr.io | linux/amd64, linux/arm64, linux/arm/v7 |
base-debian, base-debian-<version>, base-debian-<version>-<date>.<commit> | base image, built on Debian (glibc) | ghcr.io | linux/amd64, linux/arm64 |
<version> = nginx version, e.g. 1.31.10; <date>.<commit> e.g. 20261123101500.1a2b3c4
Run NGINX container:
# privileged / root user
$ docker run --name some-nginx -p 8080:80 -v ${PWD}/html:/usr/share/nginx/html:ro -d docker.io/tobi312/static-nginx:latest
# unprivileged / nginx user
$ docker run --name some-nginx -p 8080:8080 -v ${PWD}/html:/usr/share/nginx/html:ro -d docker.io/tobi312/static-nginx:latest-unprivileged
Own configuration (server blocks in /etc/nginx/conf.d/, main config /etc/nginx/nginx.conf):
$ docker run --name some-nginx -p 8080:8080 -v ${PWD}/conf.d:/etc/nginx/conf.d:ro -d docker.io/tobi312/static-nginx:latest-unprivileged
Useful commands:
# test configuration
$ docker run --rm -v ${PWD}/conf.d:/etc/nginx/conf.d:ro docker.io/tobi312/static-nginx:latest-unprivileged nginx -t
# reload configuration
$ docker exec some-nginx nginx -s reload
# show version and build options
$ docker run --rm docker.io/tobi312/static-nginx:latest nginx -V
Use in own image:
# build on alpine:
COPY --from=ghcr.io/tob1as/static-nginx:base-alpine /nginx /
# build on debian:
COPY --from=ghcr.io/tob1as/static-nginx:base-debian /nginx /
Notes for the base images:
/nginx contains nginx incl. configs, html and log symlinks, but no /run (exists in Alpine/Debian) and no user: the default nginx.conf uses user nginx;, so create the user (UID/GID 101 like the official images), e.g.:
addgroup -g 101 -S nginx && adduser -S -D -H -u 101 -h /var/cache/nginx -s /sbin/nologin -G nginx -g nginx nginxgroupadd --system --gid 101 nginx && useradd --system --gid nginx --no-create-home --home /nonexistent --shell /bin/false --uid 101 nginx/etc/ssl/certs/ca-certificates.crt) are not part of /nginx, install them in your image if needed (package ca-certificates).base-debian: the static glibc binary also works without the glibc NSS libraries (e.g. in scratch, tested on amd64 and arm64): user lookups (/etc/passwd, /etc/group) and host name resolution (/etc/hosts, DNS) are part of libc since glibc 2.34. Only other NSS sources in /etc/nsswitch.conf (e.g. LDAP, systemd) need the NSS libraries, i.e. a Debian (glibc) based image.load_module needed: the dynamic modules of nginx:mainline-alpine are compiled in statically:
ngx_http_acme_module, ngx_http_geoip_module / ngx_stream_geoip_module, ngx_http_image_filter_module, ngx_http_xslt_filter_module, ngx_http_js_module / ngx_stream_js_module (njs).
Existing configs with load_module directives must be adjusted (remove the directives), otherwise nginx does not start..dat) and GeoIP2/MMDB (.mmdb) databases.js_engine qjs;).scratch):
/docker-entrypoint.d/ scripts, no templates in /etc/nginx/templates (envsubst), NGINX_ENTRYPOINT_* variables have no effectdocker exec ... sh is not possiblecurl/wget for container healthchecks (use e.g. a TCP check or an external check)nginx/nginx-unprivileged):
101 (group 0), listen on port 8080 (HTTPS example in default.conf: 8443)/tmp/nginx.pid, temp paths (proxy_temp, client_temp, ...) in /tmp/etc/ssl/certs/ca-certificates.crt (from Alpine), also used as OpenSSL default (/etc/ssl/cert.pem), e.g. for acme_issuer or proxy_ssl_verify.Use the unprivileged image:
0 are supported (/etc/nginx, /var/cache/nginx and /run are group-writable).readOnlyRootFilesystem: true mount an emptyDir to /tmp (PID file, temp paths) and - if ACME is used - to /var/cache/nginx (default ACME state_path). securityContext:
runAsNonRoot: true
readOnlyRootFilesystem: true
allowPrivilegeEscalation: false
capabilities:
drop: ["ALL"]
volumeMounts:
- name: tmp
mountPath: /tmp
volumes:
- name: tmp
emptyDir: {}
Local build (versions: see ARG in the base Dockerfiles, can be overridden with --build-arg).
The privileged/unprivileged images use the base image ghcr.io/tob1as/static-nginx:base-alpine[-<NGINX_VERSION>] (pulled from ghcr.io, if not available locally):
# base image
$ docker build --progress=plain --target binary --build-arg NGINX_VERSION=1.31.10 -t ghcr.io/tob1as/static-nginx:base-alpine-1.31.10 -f static-nginx.base-alpine.Dockerfile .
# privileged / unprivileged image
$ docker build --progress=plain --target binary --build-arg NGINX_VERSION=1.31.10 -t local/static-nginx:latest -f static-nginx.privileged.Dockerfile .
$ docker build --progress=plain --target binary --build-arg NGINX_VERSION=1.31.10 -t local/static-nginx:latest-unprivileged -f static-nginx.unprivileged.Dockerfile .
CI (GitHub Actions):
Content type
Image
Digest
sha256:04136712b…
Size
6.3 MB
Last updated
1 day ago
docker pull tobi312/static-nginx