Skip to main content
Docker simplifies container networking by providing built-in networks and easy-to-use commands for creating custom networks. Whether you need isolated environments or seamless inter-container communication, this guide covers everything from default networks to user-defined bridges, inspection commands, and internal mechanics.

Built-in Docker Networks

Docker creates three networks upon installation: You can attach containers to any network using the --network flag:

1. Bridge Network

The bridge network is Docker’s default. Each container on this network gets an internal IP (typically in 172.17.x.x). Containers on the same bridge can communicate directly.

Port Mapping

Expose container ports to the host with -p:
This maps port 80 in the container to port 8080 on your Docker host.
If you omit -d, the container runs in the foreground.

2. Host Network

Running with --network=host makes the container share your host’s network stack:
Key points:
  • No port mapping needed
  • Ports in the container are the same as on the host
  • Cannot run multiple containers on the same host port
Using the host network removes isolation. Only use this when you trust the container’s network behavior.

3. None Network

The none network disables all external interfaces, leaving only the loopback:
Use this for maximum network isolation when no connectivity is desired.

Creating a User-Defined Bridge Network

Custom bridge networks let you isolate groups of containers and define subnets:
List all available networks:
Example output:
The image illustrates a user-defined network setup with Docker containers, showing IP addresses and connections between them.

Inspecting a Container’s Network Settings

To retrieve a container’s IP address and network details:
Search for the NetworkSettings section in the JSON output:
Use jq to filter output:

Name-Based Container Communication

Docker’s embedded DNS (at 127.0.0.11) lets containers resolve each other by name:
Here, mysql refers to the target container’s name. No static IPs required.

Under the Hood: Namespaces & veth Pairs

Docker uses Linux network namespaces to isolate containers. Communication between a container and the host bridge relies on veth (virtual Ethernet) pairs:
  • One end lives in the container’s namespace
  • The other end attaches to the host bridge
This setup ensures both isolation and connectivity.

Watch Video