CalcSnippets Search
DevOps 3 min read

Docker Networking Explained: Bridge, Host, and Overlay Networks

Learn Docker networking basics including bridge networks, host mode, overlay networks, ports, DNS, Compose networking, and practical debugging.

Containers need predictable communication

Docker networking decides how containers talk to each other, the host machine, and the outside world. Many container bugs are actually networking misunderstandings: the app listens only on localhost, the wrong port is published, a container tries to reach another service by the wrong hostname, or a database is hidden on a different network.

The default bridge network lets containers communicate through Docker-managed networking. User-defined bridge networks are usually better for local development because they provide automatic DNS between containers. In Docker Compose, services on the same network can usually reach each other by service name.

Bridge, host, and overlay serve different needs

Bridge networking is the normal local and single-host container model. It isolates containers while allowing explicit port publishing to the host. Host networking removes some isolation by sharing the host network stack, which can be useful for specialized cases but can create port conflicts and reduce portability. Overlay networks support communication across multiple Docker hosts, commonly in orchestrated environments.

Port publishing is often confused with container listening. If an app listens on 127.0.0.1 inside the container, publishing a port may not make it reachable as expected. Most containerized web apps should listen on 0.0.0.0 inside the container so Docker can route traffic to them.

  • Use service names for container-to-container communication in Compose.
  • Publish only ports that need host or external access.
  • Check which address the app listens on inside the container.
  • Use docker network inspect when debugging connectivity.

Localhost means different things

Inside a container, localhost usually means the container itself, not your laptop and not another container. If a web app container tries to reach a database at localhost, it is looking inside its own container unless host networking or special hostnames are configured. This is one of the most common Docker networking mistakes.

Use the Compose service name for another container, such as postgres or redis. Use platform-specific host gateway names when a container must reach a service running on the host. Document these addresses so teammates do not have to rediscover them.

Keep networks narrow

Not every container needs to share a network with every other container. Separate frontend, backend, database, and internal tool networks where it improves clarity and security. Avoid publishing database ports to the host unless local development truly needs it. In production, network rules should be even more deliberate.

Docker networking becomes manageable when names, ports, and networks are explicit. Debug with inspection commands, understand the path traffic takes, and avoid treating port numbers as guesses.

Document exposed ports

A Compose file or deployment manifest should make it clear which ports are internal and which are published to the host or internet. Exposing a database port for local convenience may be fine on a laptop and wrong in production. Port documentation prevents teams from copying development shortcuts into environments where they increase risk.

Keep reading

Related guides