Docker Basic Networking
Published on
Docker Basic Networking
1. The Problem: Dynamic IPs
Containers are ephemeral by nature. When a container restarts, it usually gets a new IP address.
- Hardcoding IPs in application code is fragile and incorrect.
- The moment a container restarts, your application breaks.
- This makes static IP-based communication unreliable.
Solution: Use DNS (Domain Name System) so containers communicate using container names, not IP addresses. Docker provides built-in DNS for supported networks.
2. Network Drivers
Docker supports multiple network drivers, but in real-world usage you only need to understand these three:
| Driver | Description | Use Case |
|---|---|---|
| Bridge | Default driver. Creates a private internal network on the host. | Standalone containers |
| Host | Removes network isolation. Container shares host network directly. | High performance, special network needs |
| None | Disables all networking. | Secure, fully isolated batch jobs |
Practical rule:
90% of your work will use bridge networks. The others are for edge cases.
3. The Golden Rule: User-Defined Bridges
There are two types of bridge networks in Docker, and they are not equivalent.
1. Default Bridge (bridge)
- Containers attach here automatically.
- No automatic DNS resolution.
- Containers must communicate using IP addresses.
- IPs change on restart.
- Not suitable for production.
2. User-Defined Bridge (Example: my-arch-net)
- Created manually using
docker network create. - Built-in DNS enabled.
- Containers can talk using container names.
- Stable, predictable communication.
- This is the production standard.
Rule you should memorize:
Never use the default bridge for multi-container applications.
4. Key Commands
Create a Custom Network
docker network create <network_name>
Creates a new user-defined bridge network with built-in DNS.
List All Networks
docker network ls
Shows all available Docker networks.
Run a Container on a Specific Network
docker run --network <network_name> ...
Attaches the container directly to the given network instead of the default bridge.
Inspect a Network
docker network inspect <network_name>
Displays:
- Connected containers
- Container IP addresses
- Network configuration
By - Chinmay Bagad
Thank you for reading. This article is part of the PaperAstro starter template.