December 5, 2026

Docker Networking Explained: Default Bridge, User-Defined Networks, Host and None, Tested

Shipping containers on a dock linked by colored cables at dusk

Two containers started side by side could ping each other’s IP addresses, but ping web2 from the first one failed with “bad address”. Connected to a network created with one command, the same name resolved instantly. A third container on another network could not be reached at all. And a web server published on 127.0.0.1:8085 answered on the host while the same container’s port 80 on the host did not. Those four results cover most of what trips people up about Docker networking. Every one came from containers run for this post, and the output shown is what they printed.

Video: CodeLucky on YouTube

The networks Docker starts with

bridge, host, none

docker network ls on a fresh daemon lists three built-in networks: bridge, using the bridge driver; host, using the host driver; and none, using the null driver. A container started without --network joins bridge, known as the default bridge.

The default bridge

Two containers, web1 and web2, started with no network options, landed on the default bridge with addresses 172.17.0.2 and 172.17.0.3. Pinging by address worked:

$ docker exec web1 busybox ping -c1 172.17.0.3
1 packets transmitted, 1 packets received, 0% packet loss

Pinging by name did not:

$ docker exec web1 busybox ping -c1 web2
ping: bad address 'web2'

Docker’s documentation on the bridge driver states this directly: containers on the default bridge network can only access each other by IP addresses, unless the --link option is used, which it calls legacy. Addresses on the default bridge are handed out at start time and can change on restart, so anything that hard-codes them breaks.

Elevator lobby with floor directory signage

User-defined networks

Names that resolve

The fix is one command. A network created with docker network create appnet got the subnet 172.19.0.0/16. With both containers connected to it, the name worked:

$ docker exec web1 busybox ping -c1 web2
PING web2 (172.19.0.3): 56 data bytes
1 packets transmitted, 1 packets received, 0% packet loss

The same documentation lists this as the first advantage of user-defined bridges: they provide automatic DNS resolution between containers, by name or alias. Inside the container, /etc/resolv.conf showed why: nameserver 127.0.0.11, Docker’s embedded DNS server, which answers for container names on the networks the container belongs to.

Isolation between networks

The documentation’s second advantage is isolation. It notes that every container without --network lands on the default bridge, which is a risk because unrelated stacks, services and containers are then able to communicate. A third container, web3, was started on a separate network, appnet2, at 172.20.0.2. From web1:

$ docker exec web1 busybox ping -c1 172.20.0.2
1 packets transmitted, 0 packets received, 100% packet loss

Different user-defined networks cannot reach each other by default. A web front end and a database can share one network; a second, unrelated application on another network cannot see either. A container that needs to talk to both joins both, as web1 did with bridge and appnet, and ends up with one address on each:

web1 appnet=172.19.0.2 bridge=172.17.0.2

Docker Compose creates a user-defined network for each project automatically, which is why services in one Compose file can reach each other by service name without any configuration.

Publishing ports

Reaching a container from the host

A container’s ports are not reachable from outside its network unless they are published. A small web server listening on port 80 inside the container, started with -p 127.0.0.1:8085:80, answered on the host:

$ curl http://127.0.0.1:8085/
hello-from-container
$ docker port pub1
80/tcp -> 127.0.0.1:8085

Port 80 on the host itself returned nothing; only the published mapping led into the container. Underneath, Docker had added a NAT rule to the host’s firewall: iptables -t nat -S DOCKER listed a DNAT rule sending traffic for 127.0.0.1:8085 to 172.17.0.4:80, the container’s address.

The default is open to the world

The 127.0.0.1 in that flag matters. Docker’s port publishing documentation warns that publishing container ports is insecure by default: a published port becomes available not only to the Docker host but to the outside world. Including the localhost address in the flag limits it to the host. A database published with -p 5432:5432 on a server with a public address is published to the internet, and because Docker writes its own firewall rules, a host firewall configured separately may not be in the path at all.

Container to container needs no publishing

Containers on the same user-defined network reach each other on any port the target listens on, published or not. Publishing is for traffic entering from outside the Docker network. A database that only the application container uses should be on the application’s network and not published at all.

Gate

Reaching the host from a container

The gateway address

Every bridge network has a gateway on the host. docker network inspect bridge reported the default bridge’s subnet as 172.17.0.0/16 with gateway 172.17.0.1, and the routing table inside a container on that network sent everything not local to 172.17.0.1. From a container’s point of view, that address is the host.

host.docker.internal

Rather than hard-coding the address, a container can be given a name for it. Started with --add-host host.docker.internal:host-gateway, the container’s /etc/hosts gained the line 172.17.0.1 host.docker.internal, and a request to a web server running on the host at port 8079 returned the server’s HTML page.

The service that only listens on localhost

The same request to a second server on the host, one bound to 127.0.0.1:8078, failed:

wget: can't connect to remote host (172.17.0.1): Connection refused

The container’s traffic arrived on the host’s bridge address, 172.17.0.1, not on 127.0.0.1, so a service listening only on localhost never saw it. It is the mirror image of the container-side problem in the next section: a service meant to be reached from containers has to listen on an address they can reach, either all interfaces or the bridge address specifically, and then be protected by the host’s firewall instead of by its bind address.

Host and none

–network host

With host networking, the container skips Docker’s network setup entirely. Listing network interfaces from inside a --network host container returned exactly the host’s own list, eth0, lo, docker0 and the rest. Docker’s documentation explains the trade: the container’s network stack isn’t isolated from the Docker host, it shares the host’s network namespace, and it gets no IP address of its own. A server binding port 80 in such a container binds port 80 on the host.

The same page notes that because there is no separate address, port mapping does not apply: -p and the related options are ignored, with a warning that published ports are discarded. Host mode removes the NAT hop, which can matter for performance or for software that needs to see real client addresses, at the cost of all the isolation above.

–network none

At the other extreme, --network none gives the container a loopback interface and nothing else. The interface list from inside was just lo. It suits batch jobs that process files and should have no way to reach any network.

Wall of illuminated hotel room keys in wooden cubbies

What the host sees

A virtual cable per container

On the host, the default bridge is an ordinary Linux bridge interface named docker0, holding the gateway address 172.17.0.1/16. Each container is plugged into it with a virtual Ethernet pair, one end inside the container as eth0 and the other on the host with a generated name. With no containers running, ip -br link listed no veth interfaces. Two containers later it listed two, vethb599d32 and veth2601f56, and bridge link showed both with master docker0. Removing the containers removed the pairs; the count went back to zero.

Matching a container to its interface

Inside a container, /sys/class/net/eth0/iflink holds the interface index of the other end of its pair. For the first test container it read 74, and bridge link on the host listed interface 74: as vethb599d32. That lookup is how a host-side capture can be pointed at exactly one container’s traffic: tcpdump -i vethb599d32 sees everything that container sends and receives, and nothing else, using the techniques in the post on tcpdump basics.

User-defined networks work the same way, each with its own bridge interface, named br- followed by part of the network’s ID. Two such bridges were visible on the test host during the earlier tests. Separate bridges are the starting point for the isolation seen earlier between appnet and appnet2; Docker’s own packet-filtering rules on the host keep traffic from being forwarded from one to the other.

Common problems, traced to their cause

What the tests point to

  • “Name does not resolve” between containers: they are on the default bridge. Put them on a user-defined network.
  • “Connection refused” from another container: the service inside is listening on 127.0.0.1 instead of all interfaces, so only its own container can reach it. That produces the same refused connections covered in the post on nginx 502 errors.
  • A port reachable from the internet that should not be: it was published without 127.0.0.1:.
  • -p seemingly ignored: the container is on --network host.
  • One container can reach another’s address but not by name, after a restart: the address changed, and only names are stable.

Building small images to run in all of these setups is covered in the post on Dockerfile layer caching.

Sources

  • Bridge network driver, Docker Docs: https://docs.docker.com/engine/network/drivers/bridge/
  • Host network driver, Docker Docs: https://docs.docker.com/engine/network/drivers/host/
  • Port publishing and mapping, Docker Docs: https://docs.docker.com/engine/network/port-publishing/

719 Posts

Peter Kalafatis writes and edits X9M8. He holds a bachelor's degree from LIU Post and a master's in Media Studies from The New School, with academic work in the philosophy of science, human behavior, AI, and memetics.

View All Posts

Leave a Reply

Your email address will not be published. Required fields are marked *