CalcSnippets Search
DevOps 3 min read

Docker Networking Explained: Bridge, Host, and Overlay Networks

Understand Docker networking modes, container DNS, port publishing, service communication, and common local networking mistakes.

Docker networking defines who can talk to whom

Containers need network rules for reaching other containers, the host machine, and external services. Docker provides several network drivers, but most local development starts with bridge networking. Containers on the same user-defined bridge network can usually reach each other by container or service name.

Port publishing is a separate concept. When you publish 8080:80, traffic to port 8080 on the host is forwarded to port 80 inside the container. Other containers on the same network do not need that host mapping; they can usually call the container's internal port directly.

Common network modes

  • Bridge networks are the standard single-host container network.
  • Host networking removes container network isolation and uses the host network directly.
  • Overlay networks connect containers across multiple Docker hosts in orchestrated setups.
  • None networking disables network access for isolated workloads.

The localhost trap

Inside a container, localhost means the container itself, not your laptop and not another container. If an app container needs to reach a database container, use the database service name on the shared network. If a container needs to reach a service on the host machine, use the platform-supported host address for that environment.

This mistake is common because developers think from the host perspective. Docker networking requires thinking from the container perspective. Ask where the code is running, what name it is calling, which port is open inside the target container, and whether both containers share a network.

Debug the path step by step

When a service cannot connect, check name resolution, port mapping, container logs, firewall rules, and whether the target process is listening on the expected interface. A process bound only to 127.0.0.1 inside a container may not behave the way you expect from outside.

Docker networking is easiest when you draw the path: browser to host port, host port to container port, container to service name, or container to external network. Once the path is clear, debugging becomes much less mysterious.

Keep development and production differences visible

Local Docker networking is not the same as Kubernetes, ECS, or a production VM network. Service names, DNS behavior, ingress rules, and load balancers may differ. That is fine as long as the differences are known and documented.

Avoid hardcoding local-only hostnames into application code. Put hostnames and ports in configuration so the same image can run in different environments. Good networking habits keep containers portable instead of tying them to one laptop setup.

For teams, include a short networking note in the README: which service names exist, which ports are exposed to the host, and how containers reach host services. This prevents every new developer from rediscovering the same localhost confusion.

When debugging network failures, test from inside the container as well as from the host. The two perspectives often reveal different problems, especially around DNS names and exposed ports.

Keep reading

Related guides