Docker Networking, SDN & Container Communication — Hands-On Guide
As part of my Docker learning journey, I practiced Docker networking, network drivers, custom bridge networks, container-to-container communication, SDN, Docker Compose, and container lifecycle.
This hands-on practice helped me understand how containers communicate internally and how Docker manages networking behind the scenes.
1. Basic Docker Networking
Docker networking allows containers to communicate with:
- Other containers
- The Docker host
- External networks and the Internet
When Docker is installed, it normally provides some default networks.
To view them:
docker network lsTypical output:
NETWORK ID NAME DRIVER SCOPE
xxxxxx bridge bridge local
xxxxxx host host local
xxxxxx none null localThese default networks provide different networking options depending on the requirement.
2. Docker Network Drivers
Docker provides different network drivers for different use cases.
Driver Purpose
|----------|----------------------------------------------------------------
bridge Default networking option for containers on a single Docker host
host Container shares the host's network namespace
none Container has no network connectivity
overlay Used for communication between containers across multiple
Docker hosts
macvlan Gives containers their own MAC address and makes them appear
as physical devices on the networkFor basic container-to-container communication, the bridge driver is commonly used.
3. Creating a Custom Bridge Network
Docker’s default bridge network is useful, but creating a custom bridge network provides better control and built-in DNS-based communication between containers.
I created a custom network using:
docker network create --driver bridge --subnet 10.1.2.0/24 lwnetBreaking down the command:
docker network create→ Creates a Docker network--driver bridge→ Uses the bridge driver--subnet 10.1.2.0/24→ Defines the network subnetlwnet→ Name of the network
The /24 subnet provides 254 usable IPv4 addresses.
To verify the network:
docker network lsFor detailed information:
docker network inspect lwnet4. Creating Two Containers on lwnet
I created two Ubuntu containers and connected them directly to the custom network:
docker run -dit --name c1 --network lwnet ubuntu
docker run -dit --name c2 --network lwnet ubuntuThe network can be visualized as:
lwnet
10.1.2.0/24
|
┌───────┴───────┐
↓ ↓
c1 c2
10.1.2.2 10.1.2.3The actual IP addresses can be checked with:
docker network inspect lwnet5. Testing Container-to-Container Communication
To test communication, I entered the first container:
docker exec -it c1 bashUbuntu containers may not have ping installed by default, so I installed it:
apt update
apt install iputils-ping -yThen I tested connectivity to the second container:
ping 10.1.2.3Successful ICMP replies confirm that the containers can communicate through the same Docker network.
6. Communication Using Container Names
A useful feature of a user-defined bridge network is Docker’s embedded DNS.
Instead of using the container’s IP address, I can use its name:
ping c2Similarly, from c2:
ping c1Docker resolves the container name to its current IP address.
This is useful because container IP addresses can change when containers are recreated, while the service or container name can remain the same.
7. SDN — Software-Defined Networking
SDN stands for Software-Defined Networking.
SDN is an approach where network control is managed through software rather than being tightly coupled to individual network hardware devices.
A simplified SDN architecture looks like:
SDN Controller
|
┌────────────┼────────────┐
↓ ↓ ↓
Network Network Network
Device Device DeviceDocker networking uses software-based networking concepts to dynamically create and manage container networks.
On Linux, technologies such as:
- Network namespaces
- Virtual Ethernet pairs
- Linux bridges
- Routing
- Firewall rules
help implement container networking.
8. Docker Compose
Modern applications often require multiple containers.
For example:
Frontend
↓
Backend
↓
DatabaseManaging every container manually can become difficult.
Docker Compose allows multiple services to be defined and managed through a YAML configuration file.
Get Prateek Rajput’s stories in your inbox
Join Medium for free to get updates from this writer.
Example:
services:
web:
image: nginx
ports:
- "8080:80" db:
image: postgres
environment:
POSTGRES_PASSWORD: secretStart the services:
docker compose up -dCheck the services:
docker compose psStop and remove the application:
docker compose downCompose also creates a network for the application, allowing services to communicate using their service names.
For example:
db:5432can be used to reach the PostgreSQL service instead of manually finding its container IP.
9. docker info
Another useful Docker command is:
docker infoIt displays detailed information about the Docker environment and daemon.
It can show:
- Number of containers
- Running and stopped containers
- Number of images
- Docker Server version
- Storage driver
- Cgroup driver
- Operating system
- CPU and memory information
- Docker root directory
- Network information
- Security options
There is an important difference between:
docker versionand:
docker infodocker version focuses on Docker client/server version information, while docker info provides broader information about the Docker environment.
10. Docker Container Lifecycle
A container’s lifecycle is closely tied to its main process.
For example:
docker run ubuntu sleep 30The container runs while the sleep process is running.
After 30 seconds:
sleep process exits
↓
container stopsThe stopped container normally remains available:
docker ps -aIt can then be removed manually:
docker rm <container>If automatic removal is required, use:
docker run --rm ubuntu sleep 30After the main process exits, Docker automatically removes the container.
The key concept is:
Main process exits → Container stops--rm + process exits → Container is removed11. Useful Docker Networking Commands
Some commands I practiced during this topic are:
# List networks
docker network ls# Inspect a network
docker network inspect lwnet# Create a network
docker network create --driver bridge --subnet 10.1.2.0/24 lwnet# Connect an existing container
docker network connect lwnet c1# Disconnect a container
docker network disconnect lwnet c1# Remove a network
docker network rm lwnet# Inspect container information
docker inspect c1
12. Interview Questions
What is Docker networking?
Docker networking provides communication between containers, the Docker host, and external networks.
What is a bridge network?
A bridge network provides networking between containers on the same Docker host.
Why use a custom bridge network?
It provides isolated networking and Docker’s embedded DNS, allowing containers to communicate using names.
What is SDN?
Software-Defined Networking is a software-based approach to controlling and managing network behavior.
What happens when a container’s main process exits?
The container stops. It is automatically removed only when it was started with the --rm option.
What is Docker Compose?
Docker Compose is used to define and manage multi-container applications using a YAML configuration file.
Conclusion
This hands-on session helped me connect several important Docker concepts:
Docker Networking
↓
Network Drivers
↓
Custom Bridge Network
↓
Container-to-Container Communication
↓
Docker DNS
↓
SDN Concepts
↓
Docker Compose
↓
Container LifecycleUnderstanding Docker networking is an important step toward working with containerized applications, microservices, cloud platforms, and DevOps environments.
Consistent hands-on practice is helping me strengthen my Docker and DevOps fundamentals.








