Docker Networking — In Depth
We have already covered Docker Networks earlier in this lecture. Now let's explore Docker Networking more comprehensively.
What is Docker Networking?
When we create any container inside Docker on our host machine, by default that container has some kind of networking enabled with it.
When we talk about Docker Networking, we are talking about how any container is going to interact with:
- Other containers
- The host machine
- The outside world (internet)
Core Idea
Docker Networking is all about how incoming and outgoing connections are formed.
Container ↔ Container
Container ↔ Host Machine
Container ↔ Internet
Viewing All Networks
What We See in Output
Each network contains:
- Network ID
- Network Name
- Driver type
What are Network Drivers?
Each network has a driver associated with it.
Drivers are basically the core components that define:
- How containers communicate
- How data is sent or received
- How isolation between networks is handled
Simple Explanation
Driver = Networking strategy used by Docker
Default Docker Networks
By default, Docker creates three networks for us:
1. bridge (Most Common)
- Default network for containers
- Provides isolation between containers
- Allows communication via IP or container name (within same network)
Used when we don’t specify a network
2. host
- Removes network isolation
- Container uses host machine’s network directly
- No port mapping required
Container shares host IP directly
3. none
- Disables networking completely
- Container has no external or internal network access
Summary of Default Networks
| Network | Purpose | Key Feature |
|---|
| bridge | Default container network | Container isolation with communication |
| host | Direct host networking | No isolation |
| none | No networking | Fully isolated container |
How Docker Networking Works
When a container is created:
- Docker assigns it to a network (default: bridge)
- Container gets an internal IP address
- Containers in the same network can communicate
- External access is controlled via port mapping (
-p)
Why Docker Networking is Important
Without networking:
- Containers cannot talk to each other
- Microservices cannot communicate
- Databases cannot be accessed from applications
With networking:
- Containers communicate seamlessly
- Services can be isolated yet connected
- Scalable architecture becomes possible
Real Example
Node.js App Container
↓
Docker Network (bridge / custom)
↓
MongoDB Container
This allows:
- Node.js → MongoDB communication
- Without exposing MongoDB publicly
- Secure internal communication
Key Takeaway
Docker Networking controls:
- Container-to-container communication
- Host-to-container communication
- Internet access for containers
It is the foundation of multi-container applications in Docker.