Network Isolation with Docker Internal Networks
Create isolated Docker networks with --internal: no default route, no egress — but container-to-container traffic and embedded DNS still work. Proven with hands-on tests.
Published on • November 19, 2026
AI Assistant

A database container with internet access can exfiltrate data; a database container on an --internal network can’t go anywhere it isn’t explicitly attached to. One flag buys you that — no default route, no NAT, no firewall rule spelunking. What the flag does not buy you is just as important, so this post proves both sides with live tests.
What —internal actually does
The docker network create reference is precise about the mechanism:
Containers on an internal network may communicate between each other, but not with any other network, as no default route is configured and firewall rules are set up to drop all traffic to or from other networks. Communication with the gateway IP address (and thus appropriately configured host services) is possible, and the host may communicate with any container IP directly.
Three consequences hide in there: peer traffic works, egress dies, but the host is not isolated from the container — and that distinction matters later. Create one and it’s a normal bridge network with a flag on it:
docker network create --internal demo-internal
docker network inspect demo-internal --format 'Internal={{.Internal}}'
Internal=true
Prove there’s no egress
Run a container and look at its routing table — there is no default line:
docker run -dit --name int1 --network demo-internal alpine ash
docker exec int1 ip route
172.30.0.0/16 dev eth0 scope link src 172.30.0.2
With no default route, outbound connections fail before they leave the namespace:
docker exec int1 wget -T 5 -q -O - http://93.184.216.34
wget: can't connect to remote host (93.184.216.34): Network unreachable
Note the failure mode: that’s the kernel’s routing table refusing the packet, not a firewall rule dropping it after a timeout. With no default route there is simply no path to send the packet down — enforcement you can read straight off ip route.
DNS deserves an honest test rather than an assumption. The container still uses Docker’s embedded resolver at 127.0.0.11, and peer names resolve fine:
docker run -dit --name int2 --network demo-internal alpine ash
docker exec int1 ping -c 2 int2
PING int2 (172.30.0.3): 56 data bytes
64 bytes from 172.30.0.3: seq=0 ttl=64 time=0.085 ms
But an external lookup failed outright in testing on Docker Engine 29:
docker exec int1 nslookup example.com
Server: 127.0.0.11
Address: 127.0.0.11:53
** server can't find example.com: SERVFAIL
Treat that as observed behavior, not a guarantee — the docs don’t promise either outcome for external names on an internal network, and even a resolved address would be unusable without a route. What you can rely on: the embedded DNS keeps answering for containers on the network, which is why name-based service discovery between your database and cache keeps working. The mechanics are covered in How Docker’s embedded DNS resolves container names.
Two reachability checks complete the picture. The gateway (the host side of the bridge) answers, per the docs:
docker exec int1 ping -c 2 172.30.0.1
64 bytes from 172.30.0.1: seq=0 ttl=64 time=0.091 ms
And from the host itself, container IPs are directly reachable — --internal isolates networks from each other, not from the host:
docker run --rm --network host alpine ping -c 2 172.30.0.2
64 bytes from 172.30.0.2: seq=0 ttl=64 time=0.176 ms
The two-network pattern
Isolation without connectivity is a bunker, so the real pattern is two networks: a frontend with internet access and an internal backend network shared only with the data tier. The networking overview suggests exactly this — a frontend container on a bridge network with external access and a --internal network for backend services.
docker network create demo-front
docker run -dit --name web --network demo-front alpine ash
docker network connect demo-internal web
docker exec web ip route
default via 192.168.16.1 dev eth0
172.30.0.0/16 dev eth1 scope link src 172.30.0.4
192.168.16.0/20 dev eth0 scope link src 192.168.16.2
One interface, one default route — outbound traffic takes the frontend network, and only explicitly attached containers live on the internal one. From that dual-homed container, both paths work as intended:
docker exec web ping -c 2 int1 # internal peer by name — works
docker exec web wget -T 5 -q -O /dev/null http://example.com # egress via front — exit 0
If the container joins several networks, Docker picks the default gateway for you and it may change when connections change — set a gateway priority (gw-priority on docker run or docker network connect, default 0) to pin the egress network. In Compose it’s one attribute, documented in the Compose networking guide:
services:
worker:
image: myworker
networks:
- isolated
- public
networks:
isolated:
internal: true # No default gateway, no external connectivity
public: {}
The docs note the corollary themselves: a service attached to both an internal and a non-internal network can still reach the internet through the non-internal one.
Why not just iptables?
You could bolt iptables -I DOCKER-USER -s ... -j DROP rules onto the host. Don’t, for the same reason you don’t hand-edit Docker’s bridge rules: Docker manages those rules for you, they’re implementation details the docs tell you not to touch, and they evaporate or drift on daemon upgrades, rule reordering, or host rebuilds. Manual rules also drift across environments — the snippet that worked on your laptop never reaches staging because it lived in a shell history, and a rule added to the wrong chain silently changes nothing. --internal is declarative state — it lives in the network definition, shows up in docker network inspect, survives container recreation, travels with the Compose file so every environment gets identical isolation, and disappears cleanly with the network.
What internal does NOT protect
Being honest about the boundaries is the whole point of testing:
- Lateral movement inside the network. Everything on the same user-defined network can reach every unpublished port of everything else. If an attacker lands in one container of an internal network, the database on that same network is one connection away. Segment per tier, not per application. Concretely: containers on the same user-defined bridge expose all their ports to each other with no
-pinvolved, so a Redis bound to0.0.0.0:6379on the internal network is oneredis-cliaway from every peer. Put cache, database, and three app containers on a single internal network and you’ve rebuilt the flat topology you meant to escape — just without the internet. - Dual-homed containers. The frontend in the pattern above is a deliberate bridge into the internal network. Compromise it and the backend is reachable through it. Internal protects the network’s perimeter, not the services you intentionally route to it.
- The host. Gateway services and direct container-IP access from the host still work — by design. Don’t expose sensitive host services on the bridge gateway if internal containers shouldn’t reach them.
- DNS as a control. External names failed to resolve in my tests (SERVFAIL), but resolver behavior is an implementation detail that can vary by version and configuration. Never use “the name won’t resolve” as a security boundary — use the missing route, which is enforced in the kernel’s routing table.
The bottom line
--internal is ten seconds of work with kernel-enforced results: no default route, no NAT, peers and embedded DNS intact, host access preserved. Pair it with a normal egress network for anything that must talk outward, pin the gateway with gw-priority, and remember what it doesn’t do — isolation is per network, so give each tier its own, and treat every dual-homed container as the bridge it is.