From 2aaaac6676158201f2e901b7e84237699a6b7a75 Mon Sep 17 00:00:00 2001 From: ladydd <39373706+ladydd@users.noreply.github.com> Date: Tue, 24 Nov 2026 07:01:27 +0000 Subject: [PATCH] Warn when dind starts in a netns where another dockerd already manages iptables --- 29/dind/dockerd-entrypoint.sh | 5 +++++ dockerd-entrypoint.sh | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/29/dind/dockerd-entrypoint.sh b/29/dind/dockerd-entrypoint.sh index 14dac8ce6..4cdc72584 100755 --- a/29/dind/dockerd-entrypoint.sh +++ b/29/dind/dockerd-entrypoint.sh @@ -191,6 +191,11 @@ if [ "$1" = 'dockerd' ]; then iptables --version # so users can see whether it's legacy or not uid="$(id -u)" + if [ "$uid" = '0' ] && iptables -nL DOCKER > /dev/null 2>&1; then + # a "DOCKER" chain before our dockerd has even started means another daemon is (or was) managing iptables in this network namespace (usually "--network=host" on a host that also runs Docker); dockerd flushes and recreates its chains on startup, which wipes the other daemon's rules + echo >&2 "warning: found an existing 'DOCKER' iptables chain; another Docker daemon seems to share this network namespace (--network=host?)" + echo >&2 "warning: starting dockerd here will reset that daemon's iptables rules and can break networking for its containers" + fi if [ "$uid" != '0' ]; then # if we're not root, we must be trying to run rootless if ! command -v rootlesskit > /dev/null; then diff --git a/dockerd-entrypoint.sh b/dockerd-entrypoint.sh index 14dac8ce6..4cdc72584 100755 --- a/dockerd-entrypoint.sh +++ b/dockerd-entrypoint.sh @@ -191,6 +191,11 @@ if [ "$1" = 'dockerd' ]; then iptables --version # so users can see whether it's legacy or not uid="$(id -u)" + if [ "$uid" = '0' ] && iptables -nL DOCKER > /dev/null 2>&1; then + # a "DOCKER" chain before our dockerd has even started means another daemon is (or was) managing iptables in this network namespace (usually "--network=host" on a host that also runs Docker); dockerd flushes and recreates its chains on startup, which wipes the other daemon's rules + echo >&2 "warning: found an existing 'DOCKER' iptables chain; another Docker daemon seems to share this network namespace (--network=host?)" + echo >&2 "warning: starting dockerd here will reset that daemon's iptables rules and can break networking for its containers" + fi if [ "$uid" != '0' ]; then # if we're not root, we must be trying to run rootless if ! command -v rootlesskit > /dev/null; then