# devops / docker / networking
Mastering Docker Networking
Containers need networking so they can talk to each other and reach the outside world (like browsers, APIs, databases). Docker handles this by creating virtual networks and connecting containers to them.
Types of Docker Networks
Docker provides three default network drivers right out of the box. Choosing the correct one dictates how isolated or exposed your container's traffic will be.
Bridge
This is the most commonly used network. Docker creates a private virtual network, and each container gets its own internal IP. Containers on the same bridge network can easily talk to each other.
Host
The container uses the host machine’s IP address directly. There is absolutely no isolation at the network level; port 80 in the container is port 80 on the host machine.
None
When a container is started with no network, it has zero connectivity. It cannot talk to other containers, nor can it reach the internet. Excellent for highly secure, air-gapped tasks.
Creating Custom Networks
docker network create --driver bridge \ --subnet 192.168.50.1/24 \ --ip-range 192.168.50.128/25 \ --gateway 192.168.50.1 \ mynet
What this command does
- driver
Specifies that we are creating a bridge network for container-to-container communication.
- subnet & range
Defines a custom subnet and restricts the allocatable IP range, giving you full control over container IPs.
- gateway
Assigns a specific gateway address for traffic routing.
- name
Names the new network mynet so it can be referenced by containers later.
Networking Commands Cheat Sheet
Mastering these commands allows you to troubleshoot connectivity, assign manual IPs, and keep your host's networking stack clean.
Why assign a manual IP to a container? It is highly useful when a legacy app expects a fixed IP, when testing networking behavior, or when you need predictable container-to-container communication without relying on DNS.