What is the Docker Subnet used for?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
A Docker subnet is the IP address range assigned to a Docker network. It exists so containers on that network can receive addresses, communicate with each other, and be routed predictably by Docker’s networking layer. In practice, understanding the subnet helps with connectivity debugging, avoiding IP conflicts, and designing multi-service environments cleanly.
What the Subnet Actually Does
When Docker creates a bridge or user-defined network, it allocates an address range such as 172.18.0.0/16. Containers attached to that network get IP addresses from that range.
That subnet is used for:
- container-to-container communication
- routing within the Docker network
- network isolation between groups of containers
- avoiding address overlap when multiple Docker networks exist
Without a defined subnet, Docker would not know how to assign addresses or route packets consistently.
Default Bridge Example
Docker’s default bridge network typically uses a private subnet automatically.
The output usually includes an IPAM section showing the subnet and gateway. Containers attached to bridge receive addresses from that pool.
Creating a Custom Subnet
You can define one explicitly:
Then start a container on it:
Now the container receives an address from 192.168.100.0/24.
Why You Might Want a Custom Subnet
Custom subnets are useful when:
- you want predictable network segmentation
- default ranges collide with VPN or office network ranges
- multiple Docker environments must coexist cleanly
- external routing rules depend on known private ranges
This is especially common on developer laptops that connect to corporate VPNs.
Container Discovery Usually Uses DNS, Not Fixed IPs
Even though Docker subnets assign IP addresses, most application code should use container names or service names rather than hard-coded IPs.
For example in Docker Compose, services resolve each other by name on the network. The subnet still matters underneath, but DNS-based naming is more stable than fixed addressing.
Docker Compose Example
Here both services share a custom subnet, but they should still talk using db and api as hostnames instead of fixed IPs.
Gateway and Routing
A subnet normally comes with a gateway address managed by Docker. Traffic between containers on the same network is routed internally, while traffic leaving the network goes through Docker’s NAT and host routing rules.
That is why subnet design can affect connectivity to outside networks and why overlapping ranges can break communication in confusing ways.
Common Debugging Scenario
If containers cannot reach each other or a host service, inspect the network:
Look for:
- assigned container IP
- configured subnet
- gateway
- network aliases
Many “Docker networking” bugs are really address-range conflicts or wrong network attachments.
Subnet Overlap Problems
If your Docker subnet overlaps with:
- home LAN
- office VPN
- cloud VPC
then traffic may route incorrectly. A common fix is recreating Docker networks with a non-conflicting private range.
Good private choices usually come from unused RFC 1918 space already reserved for local container use in your environment.
Common Pitfalls
- Assuming the Docker subnet is only about IP assignment and not about routing behavior.
- Hard-coding container IPs instead of using container or service DNS names.
- Letting Docker choose a subnet that overlaps with VPN or corporate network ranges.
- Forgetting that each Docker network has its own isolated subnet space.
- Debugging application connectivity without inspecting Docker network configuration first.
Summary
- A Docker subnet is the address range used by a Docker network.
- It enables container IP assignment, routing, and network isolation.
- Custom subnets help avoid conflicts and improve predictability.
- Use service names for application communication even when subnets are custom.
- Network inspection is the first step when Docker connectivity behaves unexpectedly.
Related reading
- What is the exact difference between Docker EE Enterprise Edition, Docker CE Community Edition and Docker Custom Support
- What is the Linux equivalent of host.docker.internal?
- What is the meaning of CPU and core in Kubernetes?
- What is the meaning of ImagePullBackOff status on a Kubernetes pod?
- What is the meaning of the vhost in RabbitMQ?
- What is the pod_cpu_utilization_over_pod_limit compare to pod_cpu_utilization
- What is the fastest way to send 100,000 HTTP requests in Python?
- What is the konnectivity service for Kubernetes?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.