Skip to content

Commit 387e351

Browse files
committed
Update to 20.10.0 (GA)
1 parent bf1c9f5 commit 387e351

File tree

8 files changed

+475
-0
lines changed

8 files changed

+475
-0
lines changed

20.10/Dockerfile

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#
2+
# NOTE: THIS DOCKERFILE IS GENERATED VIA "apply-templates.sh"
3+
#
4+
# PLEASE DO NOT EDIT IT DIRECTLY.
5+
#
6+
7+
FROM alpine:3.12
8+
9+
RUN apk add --no-cache \
10+
ca-certificates \
11+
# DOCKER_HOST=ssh://... -- https://github.com/docker/cli/pull/1014
12+
openssh-client
13+
14+
# set up nsswitch.conf for Go's "netgo" implementation (which Docker explicitly uses)
15+
# - https://github.com/docker/docker-ce/blob/v17.09.0-ce/components/engine/hack/make.sh#L149
16+
# - https://github.com/golang/go/blob/go1.9.1/src/net/conf.go#L194-L275
17+
# - docker run --rm debian:stretch grep '^hosts:' /etc/nsswitch.conf
18+
RUN [ ! -e /etc/nsswitch.conf ] && echo 'hosts: files dns' > /etc/nsswitch.conf
19+
20+
ENV DOCKER_VERSION 20.10.0
21+
# TODO ENV DOCKER_SHA256
22+
# https://github.com/docker/docker-ce/blob/5b073ee2cf564edee5adca05eee574142f7627bb/components/packaging/static/hash_files !!
23+
# (no SHA file artifacts on download.docker.com yet as of 2017-06-07 though)
24+
25+
RUN set -eux; \
26+
\
27+
apkArch="$(apk --print-arch)"; \
28+
case "$apkArch" in \
29+
'x86_64') \
30+
url='https://download.docker.com/linux/static/stable/x86_64/docker-20.10.0.tgz'; \
31+
;; \
32+
'armhf') \
33+
url='https://download.docker.com/linux/static/stable/armel/docker-20.10.0.tgz'; \
34+
;; \
35+
'armv7') \
36+
url='https://download.docker.com/linux/static/stable/armhf/docker-20.10.0.tgz'; \
37+
;; \
38+
'aarch64') \
39+
url='https://download.docker.com/linux/static/stable/aarch64/docker-20.10.0.tgz'; \
40+
;; \
41+
*) echo >&2 "error: unsupported architecture ($apkArch)"; exit 1 ;; \
42+
esac; \
43+
\
44+
wget -O docker.tgz "$url"; \
45+
\
46+
tar --extract \
47+
--file docker.tgz \
48+
--strip-components 1 \
49+
--directory /usr/local/bin/ \
50+
; \
51+
rm docker.tgz; \
52+
\
53+
dockerd --version; \
54+
docker --version
55+
56+
COPY modprobe.sh /usr/local/bin/modprobe
57+
COPY docker-entrypoint.sh /usr/local/bin/
58+
59+
# https://github.com/docker-library/docker/pull/166
60+
# dockerd-entrypoint.sh uses DOCKER_TLS_CERTDIR for auto-generating TLS certificates
61+
# docker-entrypoint.sh uses DOCKER_TLS_CERTDIR for auto-setting DOCKER_TLS_VERIFY and DOCKER_CERT_PATH
62+
# (For this to work, at least the "client" subdirectory of this path needs to be shared between the client and server containers via a volume, "docker cp", or other means of data sharing.)
63+
ENV DOCKER_TLS_CERTDIR=/certs
64+
# also, ensure the directory pre-exists and has wide enough permissions for "dockerd-entrypoint.sh" to create subdirectories, even when run in "rootless" mode
65+
RUN mkdir /certs /certs/client && chmod 1777 /certs /certs/client
66+
# (doing both /certs and /certs/client so that if Docker does a "copy-up" into a volume defined on /certs/client, it will "do the right thing" by default in a way that still works for rootless users)
67+
68+
ENTRYPOINT ["docker-entrypoint.sh"]
69+
CMD ["sh"]

20.10/dind-rootless/Dockerfile

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#
2+
# NOTE: THIS DOCKERFILE IS GENERATED VIA "apply-templates.sh"
3+
#
4+
# PLEASE DO NOT EDIT IT DIRECTLY.
5+
#
6+
7+
FROM docker:20.10-dind
8+
9+
# busybox "ip" is insufficient:
10+
# [rootlesskit:child ] error: executing [[ip tuntap add name tap0 mode tap] [ip link set tap0 address 02:50:00:00:00:01]]: exit status 1
11+
RUN apk add --no-cache iproute2
12+
13+
# "/run/user/UID" will be used by default as the value of XDG_RUNTIME_DIR
14+
RUN mkdir /run/user && chmod 1777 /run/user
15+
16+
# create a default user preconfigured for running rootless dockerd
17+
RUN set -eux; \
18+
adduser -h /home/rootless -g 'Rootless' -D -u 1000 rootless; \
19+
echo 'rootless:100000:65536' >> /etc/subuid; \
20+
echo 'rootless:100000:65536' >> /etc/subgid
21+
22+
RUN set -eux; \
23+
\
24+
apkArch="$(apk --print-arch)"; \
25+
case "$apkArch" in \
26+
'x86_64') \
27+
url='https://download.docker.com/linux/static/stable/x86_64/docker-rootless-extras-20.10.0.tgz'; \
28+
;; \
29+
*) echo >&2 "error: unsupported architecture ($apkArch)"; exit 1 ;; \
30+
esac; \
31+
\
32+
wget -O rootless.tgz "$url"; \
33+
\
34+
tar --extract \
35+
--file rootless.tgz \
36+
--strip-components 1 \
37+
--directory /usr/local/bin/ \
38+
'docker-rootless-extras/rootlesskit' \
39+
'docker-rootless-extras/rootlesskit-docker-proxy' \
40+
'docker-rootless-extras/vpnkit' \
41+
; \
42+
rm rootless.tgz; \
43+
\
44+
rootlesskit --version; \
45+
vpnkit --version
46+
47+
# pre-create "/var/lib/docker" for our rootless user
48+
RUN set -eux; \
49+
mkdir -p /home/rootless/.local/share/docker; \
50+
chown -R rootless:rootless /home/rootless/.local/share/docker
51+
VOLUME /home/rootless/.local/share/docker
52+
USER rootless

20.10/dind/Dockerfile

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#
2+
# NOTE: THIS DOCKERFILE IS GENERATED VIA "apply-templates.sh"
3+
#
4+
# PLEASE DO NOT EDIT IT DIRECTLY.
5+
#
6+
7+
FROM docker:20.10
8+
9+
# https://github.com/docker/docker/blob/master/project/PACKAGERS.md#runtime-dependencies
10+
RUN set -eux; \
11+
apk add --no-cache \
12+
btrfs-progs \
13+
e2fsprogs \
14+
e2fsprogs-extra \
15+
iptables \
16+
openssl \
17+
shadow-uidmap \
18+
xfsprogs \
19+
xz \
20+
# pigz: https://github.com/moby/moby/pull/35697 (faster gzip implementation)
21+
pigz \
22+
; \
23+
# only install zfs if it's available for the current architecture
24+
# https://git.alpinelinux.org/cgit/aports/tree/main/zfs/APKBUILD?h=3.6-stable#n9 ("all !armhf !ppc64le" as of 2017-11-01)
25+
# "apk info XYZ" exits with a zero exit code but no output when the package exists but not for this arch
26+
if zfs="$(apk info --no-cache --quiet zfs)" && [ -n "$zfs" ]; then \
27+
apk add --no-cache zfs; \
28+
fi
29+
30+
# TODO aufs-tools
31+
32+
# set up subuid/subgid so that "--userns-remap=default" works out-of-the-box
33+
RUN set -eux; \
34+
addgroup -S dockremap; \
35+
adduser -S -G dockremap dockremap; \
36+
echo 'dockremap:165536:65536' >> /etc/subuid; \
37+
echo 'dockremap:165536:65536' >> /etc/subgid
38+
39+
# https://github.com/docker/docker/tree/master/hack/dind
40+
ENV DIND_COMMIT ed89041433a031cafc0a0f19cfe573c31688d377
41+
42+
RUN set -eux; \
43+
wget -O /usr/local/bin/dind "https://raw.githubusercontent.com/docker/docker/${DIND_COMMIT}/hack/dind"; \
44+
chmod +x /usr/local/bin/dind
45+
46+
COPY dockerd-entrypoint.sh /usr/local/bin/
47+
48+
VOLUME /var/lib/docker
49+
EXPOSE 2375 2376
50+
51+
ENTRYPOINT ["dockerd-entrypoint.sh"]
52+
CMD []

20.10/dind/dockerd-entrypoint.sh

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
#!/bin/sh
2+
set -eu
3+
4+
_tls_ensure_private() {
5+
local f="$1"; shift
6+
[ -s "$f" ] || openssl genrsa -out "$f" 4096
7+
}
8+
_tls_san() {
9+
{
10+
ip -oneline address | awk '{ gsub(/\/.+$/, "", $4); print "IP:" $4 }'
11+
{
12+
cat /etc/hostname
13+
echo 'docker'
14+
echo 'localhost'
15+
hostname -f
16+
hostname -s
17+
} | sed 's/^/DNS:/'
18+
[ -z "${DOCKER_TLS_SAN:-}" ] || echo "$DOCKER_TLS_SAN"
19+
} | sort -u | xargs printf '%s,' | sed "s/,\$//"
20+
}
21+
_tls_generate_certs() {
22+
local dir="$1"; shift
23+
24+
# if ca/key.pem || !ca/cert.pem, generate CA public if necessary
25+
# if ca/key.pem, generate server public
26+
# if ca/key.pem, generate client public
27+
# (regenerating public certs every startup to account for SAN/IP changes and/or expiration)
28+
29+
# https://github.com/FiloSottile/mkcert/issues/174
30+
local certValidDays='825'
31+
32+
if [ -s "$dir/ca/key.pem" ] || [ ! -s "$dir/ca/cert.pem" ]; then
33+
# if we either have a CA private key or do *not* have a CA public key, then we should create/manage the CA
34+
mkdir -p "$dir/ca"
35+
_tls_ensure_private "$dir/ca/key.pem"
36+
openssl req -new -key "$dir/ca/key.pem" \
37+
-out "$dir/ca/cert.pem" \
38+
-subj '/CN=docker:dind CA' -x509 -days "$certValidDays"
39+
fi
40+
41+
if [ -s "$dir/ca/key.pem" ]; then
42+
# if we have a CA private key, we should create/manage a server key
43+
mkdir -p "$dir/server"
44+
_tls_ensure_private "$dir/server/key.pem"
45+
openssl req -new -key "$dir/server/key.pem" \
46+
-out "$dir/server/csr.pem" \
47+
-subj '/CN=docker:dind server'
48+
cat > "$dir/server/openssl.cnf" <<-EOF
49+
[ x509_exts ]
50+
subjectAltName = $(_tls_san)
51+
EOF
52+
openssl x509 -req \
53+
-in "$dir/server/csr.pem" \
54+
-CA "$dir/ca/cert.pem" \
55+
-CAkey "$dir/ca/key.pem" \
56+
-CAcreateserial \
57+
-out "$dir/server/cert.pem" \
58+
-days "$certValidDays" \
59+
-extfile "$dir/server/openssl.cnf" \
60+
-extensions x509_exts
61+
cp "$dir/ca/cert.pem" "$dir/server/ca.pem"
62+
openssl verify -CAfile "$dir/server/ca.pem" "$dir/server/cert.pem"
63+
fi
64+
65+
if [ -s "$dir/ca/key.pem" ]; then
66+
# if we have a CA private key, we should create/manage a client key
67+
mkdir -p "$dir/client"
68+
_tls_ensure_private "$dir/client/key.pem"
69+
chmod 0644 "$dir/client/key.pem" # openssl defaults to 0600 for the private key, but this one needs to be shared with arbitrary client contexts
70+
openssl req -new \
71+
-key "$dir/client/key.pem" \
72+
-out "$dir/client/csr.pem" \
73+
-subj '/CN=docker:dind client'
74+
cat > "$dir/client/openssl.cnf" <<-'EOF'
75+
[ x509_exts ]
76+
extendedKeyUsage = clientAuth
77+
EOF
78+
openssl x509 -req \
79+
-in "$dir/client/csr.pem" \
80+
-CA "$dir/ca/cert.pem" \
81+
-CAkey "$dir/ca/key.pem" \
82+
-CAcreateserial \
83+
-out "$dir/client/cert.pem" \
84+
-days "$certValidDays" \
85+
-extfile "$dir/client/openssl.cnf" \
86+
-extensions x509_exts
87+
cp "$dir/ca/cert.pem" "$dir/client/ca.pem"
88+
openssl verify -CAfile "$dir/client/ca.pem" "$dir/client/cert.pem"
89+
fi
90+
}
91+
92+
# no arguments passed
93+
# or first arg is `-f` or `--some-option`
94+
if [ "$#" -eq 0 ] || [ "${1#-}" != "$1" ]; then
95+
# set "dockerSocket" to the default "--host" *unix socket* value (for both standard or rootless)
96+
uid="$(id -u)"
97+
if [ "$uid" = '0' ]; then
98+
dockerSocket='unix:///var/run/docker.sock'
99+
else
100+
# if we're not root, we must be trying to run rootless
101+
: "${XDG_RUNTIME_DIR:=/run/user/$uid}"
102+
dockerSocket="unix://$XDG_RUNTIME_DIR/docker.sock"
103+
fi
104+
case "${DOCKER_HOST:-}" in
105+
unix://*)
106+
dockerSocket="$DOCKER_HOST"
107+
;;
108+
esac
109+
110+
# add our default arguments
111+
if [ -n "${DOCKER_TLS_CERTDIR:-}" ] \
112+
&& _tls_generate_certs "$DOCKER_TLS_CERTDIR" \
113+
&& [ -s "$DOCKER_TLS_CERTDIR/server/ca.pem" ] \
114+
&& [ -s "$DOCKER_TLS_CERTDIR/server/cert.pem" ] \
115+
&& [ -s "$DOCKER_TLS_CERTDIR/server/key.pem" ] \
116+
; then
117+
# generate certs and use TLS if requested/possible (default in 19.03+)
118+
set -- dockerd \
119+
--host="$dockerSocket" \
120+
--host=tcp://0.0.0.0:2376 \
121+
--tlsverify \
122+
--tlscacert "$DOCKER_TLS_CERTDIR/server/ca.pem" \
123+
--tlscert "$DOCKER_TLS_CERTDIR/server/cert.pem" \
124+
--tlskey "$DOCKER_TLS_CERTDIR/server/key.pem" \
125+
"$@"
126+
DOCKERD_ROOTLESS_ROOTLESSKIT_FLAGS="${DOCKERD_ROOTLESS_ROOTLESSKIT_FLAGS:-} -p 0.0.0.0:2376:2376/tcp"
127+
else
128+
# TLS disabled (-e DOCKER_TLS_CERTDIR='') or missing certs
129+
set -- dockerd \
130+
--host="$dockerSocket" \
131+
--host=tcp://0.0.0.0:2375 \
132+
"$@"
133+
DOCKERD_ROOTLESS_ROOTLESSKIT_FLAGS="${DOCKERD_ROOTLESS_ROOTLESSKIT_FLAGS:-} -p 0.0.0.0:2375:2375/tcp"
134+
fi
135+
fi
136+
137+
if [ "$1" = 'dockerd' ]; then
138+
# explicitly remove Docker's default PID file to ensure that it can start properly if it was stopped uncleanly (and thus didn't clean up the PID file)
139+
find /run /var/run -iname 'docker*.pid' -delete || :
140+
141+
uid="$(id -u)"
142+
if [ "$uid" != '0' ]; then
143+
# if we're not root, we must be trying to run rootless
144+
if ! command -v rootlesskit > /dev/null; then
145+
echo >&2 "error: attempting to run rootless dockerd but missing 'rootlesskit' (perhaps the 'docker:dind-rootless' image variant is intended?)"
146+
exit 1
147+
fi
148+
user="$(id -un 2>/dev/null || :)"
149+
if ! grep -qE "^($uid${user:+|$user}):" /etc/subuid || ! grep -qE "^($uid${user:+|$user}):" /etc/subgid; then
150+
echo >&2 "error: attempting to run rootless dockerd but missing necessary entries in /etc/subuid and/or /etc/subgid for $uid"
151+
exit 1
152+
fi
153+
: "${XDG_RUNTIME_DIR:=/run/user/$uid}"
154+
export XDG_RUNTIME_DIR
155+
if ! mkdir -p "$XDG_RUNTIME_DIR" || [ ! -w "$XDG_RUNTIME_DIR" ] || ! mkdir -p "$HOME/.local/share/docker" || [ ! -w "$HOME/.local/share/docker" ]; then
156+
echo >&2 "error: attempting to run rootless dockerd but need writable HOME ($HOME) and XDG_RUNTIME_DIR ($XDG_RUNTIME_DIR) for user $uid"
157+
exit 1
158+
fi
159+
if [ -f /proc/sys/kernel/unprivileged_userns_clone ] && unprivClone="$(cat /proc/sys/kernel/unprivileged_userns_clone)" && [ "$unprivClone" != '1' ]; then
160+
echo >&2 "error: attempting to run rootless dockerd but need 'kernel.unprivileged_userns_clone' (/proc/sys/kernel/unprivileged_userns_clone) set to 1"
161+
exit 1
162+
fi
163+
if [ -f /proc/sys/user/max_user_namespaces ] && maxUserns="$(cat /proc/sys/user/max_user_namespaces)" && [ "$maxUserns" = '0' ]; then
164+
echo >&2 "error: attempting to run rootless dockerd but need 'user.max_user_namespaces' (/proc/sys/user/max_user_namespaces) set to a sufficiently large value"
165+
exit 1
166+
fi
167+
# TODO overlay support detection?
168+
exec rootlesskit \
169+
--net="${DOCKERD_ROOTLESS_ROOTLESSKIT_NET:-vpnkit}" \
170+
--mtu="${DOCKERD_ROOTLESS_ROOTLESSKIT_MTU:-1500}" \
171+
--disable-host-loopback \
172+
--port-driver=builtin \
173+
--copy-up=/etc \
174+
--copy-up=/run \
175+
${DOCKERD_ROOTLESS_ROOTLESSKIT_FLAGS:-} \
176+
"$@"
177+
elif [ -x '/usr/local/bin/dind' ]; then
178+
# if we have the (mostly defunct now) Docker-in-Docker wrapper script, use it
179+
set -- '/usr/local/bin/dind' "$@"
180+
fi
181+
else
182+
# if it isn't `dockerd` we're trying to run, pass it through `docker-entrypoint.sh` so it gets `DOCKER_HOST` set appropriately too
183+
set -- docker-entrypoint.sh "$@"
184+
fi
185+
186+
exec "$@"

0 commit comments

Comments
 (0)