Skip to content
This repository was archived by the owner on Jan 11, 2025. It is now read-only.

Commit 435a4fa

Browse files
removed dumb-init + aligned images to official one
1 parent ab994e1 commit 435a4fa

File tree

23 files changed

+342
-308
lines changed

23 files changed

+342
-308
lines changed

10-listen-on-ipv6-by-default.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/sh
2+
# vim:sw=4:ts=4:et
3+
4+
set -e
5+
6+
ME=$(basename $0)
7+
DEFAULT_CONF_FILE="etc/nginx/conf.d/default.conf"
8+
9+
# check if we have ipv6 available
10+
if [ ! -f "/proc/net/if_inet6" ]; then
11+
echo >&3 "$ME: error: ipv6 not available"
12+
exit 0
13+
fi
14+
15+
if [ ! -f "/$DEFAULT_CONF_FILE" ]; then
16+
echo >&3 "$ME: error: /$DEFAULT_CONF_FILE is not a file or does not exist"
17+
exit 0
18+
fi
19+
20+
# check if the file can be modified, e.g. not on a r/o filesystem
21+
touch /$DEFAULT_CONF_FILE 2>/dev/null || { echo >&3 "$ME: error: can not modify /$DEFAULT_CONF_FILE (read-only file system?)"; exit 0; }
22+
23+
# check if the file is already modified, e.g. on a container restart
24+
grep -q "listen \[::]\:80;" /$DEFAULT_CONF_FILE && { echo >&3 "$ME: error: IPv6 listen already enabled"; exit 0; }
25+
26+
if [ -f "/etc/os-release" ]; then
27+
. /etc/os-release
28+
else
29+
echo >&3 "$ME: error: can not guess the operating system"
30+
exit 0
31+
fi
32+
33+
echo >&3 "$ME: Getting the checksum of /$DEFAULT_CONF_FILE"
34+
35+
case "$ID" in
36+
"debian")
37+
CHECKSUM=$(dpkg-query --show --showformat='${Conffiles}\n' nginx | grep $DEFAULT_CONF_FILE | cut -d' ' -f 3)
38+
echo "$CHECKSUM /$DEFAULT_CONF_FILE" | md5sum -c - >/dev/null 2>&1 || {
39+
echo >&3 "$ME: error: /$DEFAULT_CONF_FILE differs from the packaged version"
40+
exit 0
41+
}
42+
;;
43+
"alpine")
44+
CHECKSUM=$(apk manifest nginx 2>/dev/null| grep $DEFAULT_CONF_FILE | cut -d' ' -f 1 | cut -d ':' -f 2)
45+
echo "$CHECKSUM /$DEFAULT_CONF_FILE" | sha1sum -c - >/dev/null 2>&1 || {
46+
echo >&3 "$ME: error: /$DEFAULT_CONF_FILE differs from the packages version"
47+
exit 0
48+
}
49+
;;
50+
*)
51+
echo >&3 "$ME: error: Unsupported distribution"
52+
exit 0
53+
;;
54+
esac
55+
56+
# enable ipv6 on default.conf listen sockets
57+
sed -i -E 's,listen 80;,listen 80;\n listen [::]:80;,' /$DEFAULT_CONF_FILE
58+
59+
echo >&3 "$ME: Enabled listen on IPv6 in /$DEFAULT_CONF_FILE"
60+
61+
exit 0

20-envsubst-on-templates.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
ME=$(basename $0)
6+
7+
auto_envsubst() {
8+
local template_dir="${NGINX_ENVSUBST_TEMPLATE_DIR:-/etc/nginx/templates}"
9+
local suffix="${NGINX_ENVSUBST_TEMPLATE_SUFFIX:-.template}"
10+
local output_dir="${NGINX_ENVSUBST_OUTPUT_DIR:-/etc/nginx/conf.d}"
11+
12+
local template defined_envs relative_path output_path subdir
13+
defined_envs=$(printf '${%s} ' $(env | cut -d= -f1))
14+
[ -d "$template_dir" ] || return 0
15+
if [ ! -w "$output_dir" ]; then
16+
echo >&3 "$ME: ERROR: $template_dir exists, but $output_dir is not writable"
17+
return 0
18+
fi
19+
find "$template_dir" -follow -type f -name "*$suffix" -print | while read -r template; do
20+
relative_path="${template#$template_dir/}"
21+
output_path="$output_dir/${relative_path%$suffix}"
22+
subdir=$(dirname "$relative_path")
23+
# create a subdirectory where the template file exists
24+
mkdir -p "$output_dir/$subdir"
25+
echo >&3 "$ME: Running envsubst on $template to $output_path"
26+
envsubst "$defined_envs" < "$template" > "$output_path"
27+
done
28+
}
29+
30+
auto_envsubst
31+
32+
exit 0

README.md

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ Lua is a lightweight, high-level, multi-paradigm programming language designed p
5656
- Security checks: Docker Bench Security, Snyk.
5757
- Docker Healthchecks.
5858
- Exposes default ports (`80` and `443`), easy to extend.
59-
- Runs as non-root UID/GID `32548` (selected randomly to avoid mapping to an existing user) and uses [dumb-init](https://github.com/Yelp/dumb-init) to reap zombie processes.
6059
- Support for multiple linux distros: Alpine, Amazon, CentOS, Debian, Fedora, Ubuntu.
6160
- Extra Lua Modules.
6261
- Performance Benchmarks.
@@ -169,26 +168,41 @@ $ docker run -d -p 80:80 --read-only -v $(pwd)/nginx-cache:/var/cache/nginx -v $
169168
```
170169
If you have a more advanced configuration that requires nginx to write to other locations, simply add more volume mounts to those locations.
171170

172-
### Running nginx in debug mode
171+
### Entrypoint quiet logs
173172

174-
Images since version 1.9.8 come with `nginx-debug` binary that produces verbose output when using higher log levels. It can be used with simple CMD substitution:
173+
Since version 1.19.0, a verbose entrypoint was added. It provides information on what's happening during container startup. You can silence this output by setting environment variable `NGINX_ENTRYPOINT_QUIET_LOGS`:
175174
```console
176-
$ docker run --name my-nginx -v /host/path/nginx.conf:/etc/nginx/nginx.conf:ro -d nginx nginx-debug -g 'daemon off;'
175+
$ docker run -d -e NGINX_ENTRYPOINT_QUIET_LOGS=1 nginx
177176
```
178-
Similar configuration in docker-compose.yml may look like this:
179-
```yaml
180-
web:
181-
image: nginx
182-
volumes:
183-
- ./nginx.conf:/etc/nginx/nginx.conf:ro
184-
command: [nginx-debug, '-g', 'daemon off;']
177+
178+
### User and group id
179+
180+
Since 1.17.0, both alpine- and debian-based images variants use the same user and group ids to drop the privileges for worker processes:
181+
```console
182+
$ id
183+
uid=101(nginx) gid=101(nginx) groups=101(nginx)
185184
```
186185

187-
### Entrypoint quiet logs
186+
### Running nginx as a non-root user
188187

189-
Since version 1.19.0, a verbose entrypoint was added. It provides information on what's happening during container startup. You can silence this output by setting environment variable `NGINX_ENTRYPOINT_QUIET_LOGS`:
188+
It is possible to run the image as a less privileged arbitrary UID/GID. This, however, requires modification of nginx configuration to use directories writeable by that specific UID/GID pair:
190189
```console
191-
$ docker run -d -e NGINX_ENTRYPOINT_QUIET_LOGS=1 nginx
190+
$ docker run -d -v $PWD/nginx.conf:/etc/nginx/nginx.conf nginx
191+
```
192+
where nginx.conf in the current directory should have the following directives re-defined:
193+
```nginx
194+
pid /tmp/nginx.pid;
195+
```
196+
And in the http context:
197+
```nginx
198+
http {
199+
client_body_temp_path /tmp/client_temp;
200+
proxy_temp_path /tmp/proxy_temp_path;
201+
fastcgi_temp_path /tmp/fastcgi_temp;
202+
uwsgi_temp_path /tmp/uwsgi_temp;
203+
scgi_temp_path /tmp/scgi_temp;
204+
...
205+
}
192206
```
193207

194208
## Specs
@@ -282,7 +296,6 @@ The following are the available build-time options. They can be set using the `-
282296
| NGINX_BUILD_CONFIG | `--prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --user=nginx --group=nginx --add-module=/lua-nginx-module-${VER_LUA_NGINX_MODULE} --add-module=/ngx_devel_kit-${VER_NGX_DEVEL_KIT} --with-compat --with-file-aio --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_dav_module --with-http_flv_module --with-http_geoip_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-threads` | Options to pass to nginx's `./configure` script. |
283297
| BUILD_DEPS | Differs based on the distro | List of needed packages to build properly the software. |
284298
| NGINX_BUILD_DEPS | Differs based on the distro | List of needed packages to build properly nginx. |
285-
| VER_DUMBINIT | `1.2.2` | The version of [dumb-init](https://github.com/Yelp/dumb-init) to use. |
286299
| PKG_DEPS | Differs based on the distro | List of needed packages to run properly the software. |
287300

288301
These built-from-source flavors include the following modules by default, but one can easily increase or decrease that with the custom build options above:
@@ -380,7 +393,6 @@ $ docker inspect fabiocicerchia/nginx-lua:1-alpine | jq '.[].Config.Labels'
380393
"org.label-schema.vcs-ref": "5b8a255",
381394
"org.label-schema.vcs-url": "https://github.com/fabiocicerchia/nginx-lua",
382395
"org.label-schema.version": "1.19.2-alpine3.12.0",
383-
"versions.dumb-init": "1.2.2",
384396
"versions.extended": "1",
385397
"versions.headers-more-nginx-module": "d6d7ebab3c0c5b32ab421ba186783d3e5d2c6a17",
386398
"versions.lua-nginx-module": "0.10.17",
@@ -417,7 +429,6 @@ $ docker inspect fabiocicerchia/nginx-lua:1-alpine | jq '.[].Config.Labels'
417429
| `org.label-schema.vcs-url` | URL for the source code under version control from which this container image was built. |
418430
| `org.label-schema.version` | Release identifier for the contents of the image. |
419431
| `versions.extended` | Flag to identify if extended image (which contains extra modules). |
420-
| `versions.dumb-init` | The version of [dumb-init](https://github.com/Yelp/dumb-init) used. |
421432
| `versions.headers-more-nginx-module` | The version of [headers-more-nginx-module](https://github.com/openresty/headers-more-nginx-module) used. |
422433
| `versions.lua-nginx-module` | The version of [ngx_http_lua_module](https://github.com/openresty/lua-nginx-module) used. |
423434
| `versions.lua-resty-cookie` | The version of [lua-resty-cookie](https://github.com/cloudflare/lua-resty-cookie) used. |

bin/test.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ set -x
6161

6262
OS=$1
6363
VERSIONS=()
64-
if [ "$OS" == "alpine" ]; then VERSIONS=$ALPINE
65-
elif [ "$OS" == "amazonlinux" ]; then VERSIONS=$AMAZONLINUX
66-
elif [ "$OS" == "centos" ]; then VERSIONS=$CENTOS
67-
elif [ "$OS" == "debian" ]; then VERSIONS=$DEBIAN
68-
elif [ "$OS" == "fedora" ]; then VERSIONS=$FEDORA
69-
elif [ "$OS" == "ubuntu" ]; then VERSIONS=$UBUNTU
64+
if [ "$OS" == "alpine" ]; then VERSIONS=("${ALPINE[@]}")
65+
elif [ "$OS" == "amazonlinux" ]; then VERSIONS=("${AMAZONLINUX[@]}")
66+
elif [ "$OS" == "centos" ]; then VERSIONS=("${CENTOS[@]}")
67+
elif [ "$OS" == "debian" ]; then VERSIONS=("${DEBIAN[@]}")
68+
elif [ "$OS" == "fedora" ]; then VERSIONS=("${FEDORA[@]}")
69+
elif [ "$OS" == "ubuntu" ]; then VERSIONS=("${UBUNTU[@]}")
7070
fi
7171

7272
docker images

docker-entrypoint.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/sh
2+
# vim:sw=4:ts=4:et
3+
4+
set -e
5+
6+
if [ -z "${NGINX_ENTRYPOINT_QUIET_LOGS:-}" ]; then
7+
exec 3>&1
8+
else
9+
exec 3>/dev/null
10+
fi
11+
12+
if [ "$1" = "nginx" -o "$1" = "nginx-debug" ]; then
13+
if /usr/bin/find "/docker-entrypoint.d/" -mindepth 1 -maxdepth 1 -type f -print -quit 2>/dev/null | read v; then
14+
echo >&3 "$0: /docker-entrypoint.d/ is not empty, will attempt to perform configuration"
15+
16+
echo >&3 "$0: Looking for shell scripts in /docker-entrypoint.d/"
17+
find "/docker-entrypoint.d/" -follow -type f -print | sort -n | while read -r f; do
18+
case "$f" in
19+
*.sh)
20+
if [ -x "$f" ]; then
21+
echo >&3 "$0: Launching $f";
22+
"$f"
23+
else
24+
# warn on shell scripts without exec bit
25+
echo >&3 "$0: Ignoring $f, not executable";
26+
fi
27+
;;
28+
*) echo >&3 "$0: Ignoring $f";;
29+
esac
30+
done
31+
32+
echo >&3 "$0: Configuration complete; ready for start up"
33+
else
34+
echo >&3 "$0: No files found in /docker-entrypoint.d/, skipping configuration"
35+
fi
36+
fi
37+
38+
exec "$@"

nginx/1.19.3/alpine/3.12.0/Dockerfile

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,6 @@ ARG NGINX_BUILD_DEPS="\
198198
zlib-dev"
199199
ENV NGINX_BUILD_DEPS=$NGINX_BUILD_DEPS
200200

201-
# dumb-init
202-
# https://github.com/Yelp/dumb-init
203-
ARG VER_DUMBINIT=1.2.2
204-
ENV VER_DUMBINIT=$VER_DUMBINIT
205-
206201
####################################
207202
# Build Nginx with support for LUA #
208203
####################################
@@ -378,7 +373,6 @@ LABEL maintainer="Fabio Cicerchia <[email protected]>" \
378373
org.label-schema.vcs-url="https://github.com/$DOCKER_IMAGE" \
379374
org.label-schema.version="$VER_NGINX-$DOCKER_IMAGE_OS$DOCKER_IMAGE_TAG" \
380375
versions.extended=${EXTENDED_IMAGE} \
381-
versions.dumb-init=${VER_DUMBINIT} \
382376
versions.headers-more-nginx-module=${VER_OPENRESTY_HEADERS} \
383377
versions.lua-nginx-module=${VER_LUA_NGINX_MODULE} \
384378
versions.lua-resty-cookie=${VER_CLOUDFLARE_COOKIE} \
@@ -442,16 +436,18 @@ RUN set -eux \
442436
&& mkdir -p /var/log/nginx \
443437
&& ln -sf /dev/stdout /var/log/nginx/access.log \
444438
&& ln -sf /dev/stderr /var/log/nginx/error.log \
445-
# dumb-init
446-
# ##############################################################################
447-
&& curl -Lo /usr/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v${VER_DUMBINIT}/dumb-init_${VER_DUMBINIT}_x86_64 \
448-
&& chmod +x /usr/bin/dumb-init \
449439
# create nginx user/group first, to be consistent throughout docker variants
450-
&& addgroup -g 32548 -S nginx \
451-
&& adduser -S -D -H -u 32548 -h /var/cache/nginx -s /sbin/nologin -G nginx -g nginx nginx \
440+
&& addgroup -g 101 -S nginx \
441+
&& adduser -S -D -H -u 101 -h /var/cache/nginx -s /sbin/nologin -G nginx -g nginx nginx
442+
443+
COPY docker-entrypoint.sh /
444+
COPY 10-listen-on-ipv6-by-default.sh /docker-entrypoint.d
445+
COPY 20-envsubst-on-templates.sh /docker-entrypoint.d
446+
ENTRYPOINT ["/docker-entrypoint.sh"]
447+
452448
# smoke test
453449
# ##############################################################################
454-
&& envsubst -V \
450+
RUN envsubst -V \
455451
&& nginx -V \
456452
&& nginx -t
457453

@@ -462,6 +458,4 @@ EXPOSE 80 443
462458
# Override stop signal to stop process gracefully
463459
STOPSIGNAL SIGQUIT
464460

465-
ENTRYPOINT ["dumb-init"]
466-
467461
CMD ["nginx", "-g", "daemon off;"]

nginx/1.19.3/alpine/3.12.1/Dockerfile

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,6 @@ ARG NGINX_BUILD_DEPS="\
198198
zlib-dev"
199199
ENV NGINX_BUILD_DEPS=$NGINX_BUILD_DEPS
200200

201-
# dumb-init
202-
# https://github.com/Yelp/dumb-init
203-
ARG VER_DUMBINIT=1.2.2
204-
ENV VER_DUMBINIT=$VER_DUMBINIT
205-
206201
####################################
207202
# Build Nginx with support for LUA #
208203
####################################
@@ -378,7 +373,6 @@ LABEL maintainer="Fabio Cicerchia <[email protected]>" \
378373
org.label-schema.vcs-url="https://github.com/$DOCKER_IMAGE" \
379374
org.label-schema.version="$VER_NGINX-$DOCKER_IMAGE_OS$DOCKER_IMAGE_TAG" \
380375
versions.extended=${EXTENDED_IMAGE} \
381-
versions.dumb-init=${VER_DUMBINIT} \
382376
versions.headers-more-nginx-module=${VER_OPENRESTY_HEADERS} \
383377
versions.lua-nginx-module=${VER_LUA_NGINX_MODULE} \
384378
versions.lua-resty-cookie=${VER_CLOUDFLARE_COOKIE} \
@@ -442,16 +436,18 @@ RUN set -eux \
442436
&& mkdir -p /var/log/nginx \
443437
&& ln -sf /dev/stdout /var/log/nginx/access.log \
444438
&& ln -sf /dev/stderr /var/log/nginx/error.log \
445-
# dumb-init
446-
# ##############################################################################
447-
&& curl -Lo /usr/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v${VER_DUMBINIT}/dumb-init_${VER_DUMBINIT}_x86_64 \
448-
&& chmod +x /usr/bin/dumb-init \
449439
# create nginx user/group first, to be consistent throughout docker variants
450-
&& addgroup -g 32548 -S nginx \
451-
&& adduser -S -D -H -u 32548 -h /var/cache/nginx -s /sbin/nologin -G nginx -g nginx nginx \
440+
&& addgroup -g 101 -S nginx \
441+
&& adduser -S -D -H -u 101 -h /var/cache/nginx -s /sbin/nologin -G nginx -g nginx nginx
442+
443+
COPY docker-entrypoint.sh /
444+
COPY 10-listen-on-ipv6-by-default.sh /docker-entrypoint.d
445+
COPY 20-envsubst-on-templates.sh /docker-entrypoint.d
446+
ENTRYPOINT ["/docker-entrypoint.sh"]
447+
452448
# smoke test
453449
# ##############################################################################
454-
&& envsubst -V \
450+
RUN envsubst -V \
455451
&& nginx -V \
456452
&& nginx -t
457453

@@ -462,6 +458,4 @@ EXPOSE 80 443
462458
# Override stop signal to stop process gracefully
463459
STOPSIGNAL SIGQUIT
464460

465-
ENTRYPOINT ["dumb-init"]
466-
467461
CMD ["nginx", "-g", "daemon off;"]

0 commit comments

Comments
 (0)