Skip to main content
In this lesson, we’ll explore Docker networking fundamentals: default networks, custom bridge networks, DNS resolution, and how to connect or disconnect containers from networks. By the end, you’ll understand how Docker manages container networking and how to customize it for your applications.

Listing Default Networks

Docker comes with three built-in networks: To see these networks:
Example output:

Inspecting the Bridge Network

To view details such as subnet configuration and gateway:
Key fields:
The IPAM (IP Address Management) section shows how Docker assigns subnets and gateways.

Running Containers on the Default Bridge

When you start a container without specifying a network, it’s attached to bridge:
Inspect its network settings:
Create a second container:
On the default bridge, embedded DNS is not enabled. Attempting to ping by container name fails:

Creating a User-Defined Bridge Network

User-defined bridge networks include built-in DNS and automatic name resolution. Create one with a custom subnet:
Verify its presence:

Running Containers on the Custom Network

Launch two containers on kodekloudnet:
They now receive IPs within 192.168.10.0/24, and DNS-based name resolution works:

Connecting an Existing Container to a Network

By default, containers attach only to the default bridge. To connect first to kodekloudnet:
Verify both network endpoints:
Now ping first from customfirst:

Disconnecting a Container from a Network

To detach a container:
After disconnecting, customfirst will no longer reach first on that network.

Removing Networks

Docker prevents removing networks with active endpoints. To delete kodekloudnet:
  1. Stop and remove containers:
  2. Remove the network:
You can also prune all unused user-defined networks:
docker network prune removes only user-defined networks without active containers. Default networks (bridge, host, none) are not affected.

Watch Video