Docker networking controls how containers communicate with each other and the outside world. This guide explains Docker’s network types and demonstrates how to create and manage custom networks on Ubuntu 24.04 LTS.
Tested and valid on:
- Ubuntu 24.04 LTS
Prerequisites
- Ubuntu 24.04 LTS server
- Docker Engine installed
- A user in the docker group
Step 1 – List Default Docker Networks
View the networks Docker creates automatically:
docker network ls
You will see bridge, host, and none.
Step 2 – Understand Docker Network Types
The main Docker network drivers:
- bridge — default for standalone containers on the same host
- host — container shares the host network stack
- none — no networking
- overlay — multi-host networking for Docker Swarm
- macvlan — assign a MAC address to the container
Step 3 – Create a Custom Bridge Network
Create an isolated network for your application:
docker network create myapp-network
docker network inspect myapp-network
Step 4 – Run Containers on the Custom Network
Attach containers to the network:
docker run -d --name db --network myapp-network mysql:8.0
docker run -d --name web --network myapp-network -p 80:80 nginx:latest
Containers on the same custom bridge network can reach each other by name.
Step 5 – Connect a Container to Multiple Networks
Attach a running container to another network:
docker network connect another-network web
Step 6 – Disconnect and Remove Networks
Disconnect a container from a network:
docker network disconnect myapp-network web
docker network rm myapp-network
Step 7 – Use Host Networking
Run a container using the host network directly (bypasses NAT):
docker run -d --network host nginx:latest
Conclusion
Docker networking is now clear on Ubuntu 24.04 LTS. Use custom bridge networks to isolate application tiers. Containers on the same user-defined network resolve each other by container name.