Skip to content

Commit bfe953e

Browse files
authored
Merge pull request #468 from infosiftr/better-iptables
Ignore the exit code of `modprobe` always
2 parents 458a535 + eb4c40e commit bfe953e

3 files changed

Lines changed: 99 additions & 12 deletions

File tree

‎24/dind/dockerd-entrypoint.sh‎

Lines changed: 33 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎25-rc/dind/dockerd-entrypoint.sh‎

Lines changed: 33 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dockerd-entrypoint.sh‎

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,17 +143,46 @@ if [ "$1" = 'dockerd' ]; then
143143
# XXX inject "docker-init" (tini) as pid1 to workaround https://github.com/docker-library/docker/issues/318 (zombie container-shim processes)
144144
set -- docker-init -- "$@"
145145

146-
if ! iptables -nL > /dev/null 2>&1; then
146+
iptablesLegacy=
147+
if [ -n "${DOCKER_IPTABLES_LEGACY+x}" ]; then
148+
# let users choose explicitly to legacy or not to legacy
149+
iptablesLegacy="$DOCKER_IPTABLES_LEGACY"
150+
if [ -n "$iptablesLegacy" ]; then
151+
modprobe ip_tables || :
152+
else
153+
modprobe nf_tables || :
154+
fi
155+
elif (
156+
# https://git.netfilter.org/iptables/tree/iptables/nft-shared.c?id=f5cf76626d95d2c491a80288bccc160c53b44e88#n420
157+
# https://github.com/docker-library/docker/pull/468#discussion_r1442131459
158+
for f in /proc/net/ip_tables_names /proc/net/ip6_tables_names /proc/net/arp_tables_names; do
159+
if b="$(cat "$f")" && [ -n "$b" ]; then
160+
exit 0
161+
fi
162+
done
163+
exit 1
164+
); then
165+
# if we already have any "legacy" iptables rules, we should always use legacy
166+
iptablesLegacy=1
167+
elif ! iptables -nL > /dev/null 2>&1; then
147168
# if iptables fails to run, chances are high the necessary kernel modules aren't loaded (perhaps the host is using xtables, for example)
148169
# https://github.com/docker-library/docker/issues/350
149170
# https://github.com/moby/moby/issues/26824
150171
# https://github.com/docker-library/docker/pull/437#issuecomment-1854900620
151-
if ! modprobe nf_tables; then
172+
modprobe nf_tables || :
173+
if ! iptables -nL > /dev/null 2>&1; then
174+
# might be host has no nf_tables, but Alpine is all-in now (so let's try a legacy fallback)
152175
modprobe ip_tables || :
153-
# see https://github.com/docker-library/docker/issues/463 (and the dind Dockerfile where this directory is set up)
154-
export PATH="/usr/local/sbin/.iptables-legacy:$PATH"
176+
if /usr/local/sbin/.iptables-legacy/iptables -nL > /dev/null 2>&1; then
177+
iptablesLegacy=1
178+
fi
155179
fi
156180
fi
181+
if [ -n "$iptablesLegacy" ]; then
182+
# see https://github.com/docker-library/docker/issues/463 (and the dind Dockerfile where this directory is set up)
183+
export PATH="/usr/local/sbin/.iptables-legacy:$PATH"
184+
fi
185+
iptables --version # so users can see whether it's legacy or not
157186

158187
uid="$(id -u)"
159188
if [ "$uid" != '0' ]; then

0 commit comments

Comments
 (0)