Docker warns that IPv4 forwarding is disabled
WARNING: IPv4 forwarding is disabledShort answer
Docker containers need the Linux kernel setting net.ipv4.ip_forward to be 1 on the host. The warning means dockerd saw 0. Most often a hardening file in /etc/sysctl.d resets it, or you use Docker's nftables backend, which never turns it on. In rootless mode the warning can also be wrong. Read the real value first.
Fix it fast
1Find out which cause you have
Read the kernel value on the host. 1 means forwarding is on; 0 means something has it off.
cat /proc/sys/net/ipv4/ip_forward grep -rn "ip_forward" /etc/sysctl.conf /etc/sysctl.d/ /usr/lib/sysctl.d/ /run/sysctl.d/ 2>/dev/null2Match what you see, then jump to its fix
- 1
The value is 0 and grep finds net.ipv4.ip_forward = 0 in a security-baseline file. The warning may appear only right after a reboot.A sysctl file sets ip_forward to 0 (common on hardened servers)Fix - 2
Docker was switched to the nftables firewall backend, and forwarding is 0.Docker uses the nftables backend, which does not enable forwardingFix - 3
You run Docker rootless, the host value is 0, and containers can still reach the network.Rootless Docker prints the warning although forwarding worksFix
- 1
What does the error look like?
WARNING: IPv4 forwarding is disabledIPv4 forwarding is disabled. Networking will not work.
Cause 1 of 3
A sysctl file sets ip_forward to 0 (common on hardened servers)
1Check
Docker turns forwarding on when it starts, but a sysctl file that systemd-sysctl applies later can set it back to 0. The Moby maintainers described exactly this ordering race on a host hardened to a CIS benchmark.
systemctl status systemd-sysctl --no-pager2Fix
Make the setting 1 in a file that sorts after the one that sets 0 (the last file name in lexical order wins), or exempt IP forwarding from the baseline, because Docker networking depends on it. Then apply the files.
# /etc/sysctl.d/99-docker.conf
net.ipv4.ip_forward=13Verify
Re-apply the sysctl files, restart Docker, and read the value again.
sudo systemctl restart systemd-sysctl
sudo systemctl restart docker
cat /proc/sys/net/ipv4/ip_forwardConfirmed by man7.org
Cause 2 of 3
Docker uses the nftables backend, which does not enable forwarding
1Check
With the nftables backend Docker does not enable IP forwarding itself. If forwarding is needed and off, Docker reports an error. The same happens after a move from the iptables backend, if nothing else turns forwarding on after a reboot.
cat /etc/docker/daemon.json2Fix
Set the sysctl yourself on the host and keep it in a file under /etc/sysctl.d. Also add firewall rules that block forwarding between non-Docker interfaces you do not want connected.
# /etc/sysctl.d/99-docker.conf
net.ipv4.ip_forward=1
net.ipv6.conf.all.forwarding=13Verify
Apply the file, restart Docker and start a container.
sudo systemctl restart systemd-sysctl
sudo systemctl restart docker
docker run --rm alpine trueConfirmed by docs.docker.com
Cause 3 of 3
Rootless Docker prints the warning although forwarding works
1Check
In rootless mode the network runs in a separate namespace, and affected daemon versions read the host's value instead of that namespace's value. The Moby project fixed the wrong check and tracked it for the 29.6.0 release.
docker version --format '{{.Server.Version}}'
docker run --rm alpine wget -q -O /dev/null https://example.com && echo network ok2Fix
If the test above prints network ok, the warning is harmless: update to a release that includes the fix. If it fails, you are in a different cause, so use the causes above.
# update Docker Engine through your package manager, then restart the Docker service3Verify
Run the network test again after the update.
docker run --rm alpine wget -q -O /dev/null https://example.com && echo network okConfirmed by github.com
How do I stop it coming back?
- When you apply a hardening baseline, allow net.ipv4.ip_forward=1 on Docker hosts.
- Keep the Docker setting in a clearly named /etc/sysctl.d file and review it after OS upgrades.
- When you switch Docker to the nftables backend, set the forwarding sysctls in the same change.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Servers
A Docker container port is not reachable from the host or network
The service answers inside the container but not from the host
A container port is closed to the outside until you publish it with -p or a ports entry.
3 causes, each with a fixServers
Apache logs SIGWINCH and exits on its own
the httpd container stops although nothing crashed
SIGWINCH is Apache's graceful-stop signal.
2 causes, each with a fixServers
sam local fails: Running AWS SAM projects locally requires Docker
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
sam local start-api and sam local invoke run your function inside a Docker container, so SAM stops if it cannot talk to Docker.
3 causes, each with a fixServers
dnf fails to download repo metadata in a CentOS 8 Docker build
The same Dockerfile built fine before 2022
CentOS Linux 8 reached end of life on 31 December 2021 and its content left the mirrors.
2 causes, each with a fixServers
pip install confluent-kafka fails because librdkafka/rdkafka.h is missing
pip stops while building confluent-kafka from source
The error means pip is compiling confluent-kafka from source, and the compiler cannot find the librdkafka C headers.
3 causes, each with a fixServers
Cypress says the npm package is installed but the binary is missing
Cypress binary is missing after npm install in CI or in a Docker build
The npm package is only a launcher.
3 causes, each with a fix