Skip to content
Go back

Docker Networking Essential Guide for All Skill Levels

· Updated:
By KingPin 10 min read
Docker Networking Essential Guide for All Skill Levels

Welcome aboard the Docker ship, where networking isn’t just a buzzword but a way of life! Lone sailor running Docker in standalone mode, or captain of a fleet deploying containers across multiple hosts, either way Docker has a networking model to keep your containers talking smoothly. From the cozy default network to the vast expanses of advanced overlay networks, we’ll navigate through them all. So, buckle up, and let’s get moving into the world of Docker networking! And remember, this is part two of our series, so check out part one if you haven’t yet. For extra credit, explore our resources on Kubernetes Networking and how to monitor Docker containers with cAdvisor.

Key Takeaways:

Standalone Docker Networking:

NETWORK ID NAME DRIVER SCOPE
5beee851de42 bridge bridge local

And if you’re curious about what your network interface looks like, ifconfig will show you docker0, hanging out with its IP and MAC address details.

User-defined Bridge Networks:

The Host Network:

Macvlan Network:

None Network:

Distributed Networking with Overlay Networks:

Ingress in Docker Swarm:

Docker Network Plugins:

Docker networking can be categorized into simple, intermediate, and advanced levels based on the complexity and the use cases they address. Here are 20 examples spanning these categories, each explained in detail:

Simple Docker Networking Examples

Intermediate Docker Networking Examples

Advanced Docker Networking Examples

Each of these examples represents a different level of complexity and serves specific networking needs in Docker environments, from simple setups for development to advanced configurations for large-scale, secure, and efficient production deployments.

Putting It to Work: Compose, Ports, and Debugging

The default bridge has no DNS between containers, so curl http://web/ from another container fails there and works on a user-defined bridge. Compose creates a user-defined bridge per project, and you can split services across several to build boundaries:

docker-compose.yml
services:
frontend:
image: nginx
ports:
- "80:80"
networks: [public]
api:
image: myapp-api
networks: [public, internal]
db:
image: postgres
networks: [internal]
networks:
public:
internal:

The frontend can reach api but has no path to db. The api sits on both networks and bridges them. The db is unreachable from the frontend and from outside.

Publish ports only for what the outside world needs, usually the reverse proxy. A database on the same Docker network as its app needs no ports: entry, and 5432:5432 on the host just opens a hole. Note that --network host only gives real host networking on Linux. On Mac and Windows, Docker runs in a VM, so you get the VM’s network unless you turn on Docker Desktop’s host networking option (version 4.34 and later).

Commands you will use for debugging:

Terminal window
docker network ls
docker network inspect myapp-net # members, IPs, subnet, gateway
docker network connect myapp-net mycontainer
docker network disconnect myapp-net mycontainer
docker network prune # remove unused networks

When two containers cannot talk, check these in order:

  1. Are both on the same named network, not just “a” network?
  2. Is it a user-defined bridge? Name resolution does not work on the default one.
  3. Is the hostname right? It is the container name, or the service name in Compose.
  4. Does the app listen on 0.0.0.0 inside the container? An app bound to 127.0.0.1 is unreachable from other containers.
  5. Is a host firewall blocking inter-container traffic?

Share this post on:

Send a Webmention

Written about this post on your own site? Send a webmention and it'll show up above once verified.


Previous Post
Certificate Pinning: A Secure Connection Guide
Next Post
Docker Volume Mounts: Essential Flags

Discussion

Powered by Garrul . Sign in with GitHub or Google, or post anonymously.

Related Posts