Custom Subnets, Gateways & Static Container IP Assignment
Define subnets and optionally pin static IPs when DHCP-style assignment is not enough.
In plain words
Use a custom subnet for route integration and reserve static IPs for legacy exceptions, not as normal service discovery.
Think of it like…
A static desk number works for an office that never moves; a DNS name is the receptionist routing visitors as desks are rearranged.
Where you’ve seen it
In practice, docker network create --subnet 172.28.16.0/24 --gateway 172.28.16.1 payments; docker run --network payments --ip 172.28.16.20 db:17 is the concrete move for this job: define subnets and optionally pin static IPs when DHCP-style assignment is not enough. The release is not accepted until docker network inspect payments and ip addr show inside db, then test the route back from an approved corporate VM confirms the result.
Words you’ll hear
- Subnet
- The implementation control in
docker network create --subnet 172.28.16.0/24 --gateway 172.28.16.1 payments; docker run --network payments --ip 172.28.16.20 db:17for define subnets and optionally pin static IPs when DHCP-style assignment is not enough. - Gateway
- The result to observe with
docker network inspect payments and ip addr show inside db, then test the route back from an approved corporate VM, rather than infer from a successful command alone. - Static IP
- The production boundary exposed when using 10.0.0.0/8 out of habit on a host connected to a 10/8 VPN, or reserving the same address in two compose project networks.
Visual diagram
Theory & deep dive
Subnet control path
The concrete mechanism is docker network create --subnet 172.28.16.0/24 --gateway 172.28.16.1 payments; docker run --network payments --ip 172.28.16.20 db:17. The observable result is docker network inspect payments and ip addr show inside db, then test the route back from an approved corporate VM; if those disagree, inspect the runtime evidence before changing unrelated settings.
Define subnets and optionally pin static IPs when DHCP-style assignment is not enough. Keep Subnet, Gateway and Static IP in the same deployment record so the intent and the observed state cannot drift apart.
docker network create --subnet 172.28.16.0/24 --gateway 172.28.16.1 payments; docker run --network payments --ip 172.28.16.20 db:17
docker network inspect payments and ip addr show inside db, then test the route back from an approved corporate VM, not with command success alone.Static IP failure boundary
A static IP creates ordering and reuse problems during rescheduling, and an overlapping subnet sends traffic toward Docker instead of the corporate route. Static assignment also bypasses DNS failover unless the rest of the stack updates routing deliberately. The narrow failure to design for is using 10.0.0.0/8 out of habit on a host connected to a 10/8 VPN, or reserving the same address in two compose project networks.
Accept this compromise explicitly: Custom addressing integrates legacy routing; stable names and IPAM make general workloads safer and easier to reschedule. The controlled check-docker network inspect payments and ip addr show inside db, then test the route back from an approved corporate VM-also identifies the point where a different design is safer.
Exercise this failure safely: using 10.0.0.0/8 out of habit on a host connected to a 10/8 VPN, or reserving the same address in two compose project networks.
How it works, step by step
Step 1 of 41. State the boundary
Write down why the workload needs this: A static IP creates ordering and reuse problems during rescheduling, and an overlapping subnet sends traffic toward Docker instead of the corporate route. Static assignment also bypasses DNS failover unless the rest of the stack updates routing deliberately.
- Intent
- Subnet
When to use it & trade-offs
What it is
A custom network can declare subnet, gateway and IPAM ranges; a container can request a static address on that user-defined network. Docker owns the address pool, so external routing and static assignment must avoid DHCP, VPN and peer network overlaps.
Why it matters: A static IP creates ordering and reuse problems during rescheduling, and an overlapping subnet sends traffic toward Docker instead of the corporate route. Static assignment also bypasses DNS failover unless the rest of the stack updates routing deliberately.
When to reach for it
- The fit is strongest for this job: define subnets and optionally pin static IPs when DHCP-style assignment is not enough. Pair it with
docker network inspect payments and ip addr show inside db, then test the route back from an approved corporate VMin the runbook. - Production Subnet changes should make Gateway observable through
docker network create --subnet 172.28.16.0/24 --gateway 172.28.16.1 payments; docker run --network payments --ip 172.28.16.20 db:17, rather than trusting the runtime default. - Keep a rollback example for the case where using 10.0.0.0/8 out of habit on a host connected to a 10/8 VPN, or reserving the same address in two compose project networks.
When to avoid or be careful
- Do not accept command success while the system can still fail by using 10.0.0.0/8 out of habit on a host connected to a 10/8 VPN, or reserving the same address in two compose project networks.
- Avoid erasing Static IP protection merely to dodge this cost: “Custom addressing integrates legacy routing; stable names and IPAM make general workloads safer and easier to reschedule”.
- Do not replace the evidence path-
docker network inspect payments and ip addr show inside db, then test the route back from an approved corporate VM-with a screenshot or a mutable tag.
docker network create --subnet 172.28.16.0/24 --gateway 172.28.16.1 payments; docker run --network payments --ip 172.28.16.20 db:17: practical choices
Strengths: A custom network can declare subnet, gateway and IPAM ranges; a container can request a static address on that user-defined network. Docker owns the address pool, so external routing and static assignment must avoid DHCP, VPN and peer network overlaps.
Watch out: Custom addressing integrates legacy routing; stable names and IPAM make general workloads safer and easier to reschedule.
Strengths: It can begin with docker network create --subnet 172.28.16.0/24 --gateway 172.28.16.1 payments; docker run --network payments --ip 172.28.16.20 db:17 and fewer surrounding controls.
Watch out: It silently accepts using 10.0.0.0/8 out of habit on a host connected to a 10/8 VPN, or reserving the same address in two compose project networks, which makes the result hard to reproduce after promotion.
Strengths: A static IP creates ordering and reuse problems during rescheduling, and an overlapping subnet sends traffic toward Docker instead of the corporate route. Static assignment also bypasses DNS failover unless the rest of the stack updates routing deliberately.
Watch out: The platform adds an ownership and debugging layer; retain docker network inspect payments and ip addr show inside db, then test the route back from an approved corporate VM as the direct check.
Interview signals & numbers to know
When this topic comes up
- docker network create --subnet 172.28.16.0/24 --gateway 172.28.16.1 payments; docker run --network payments --ip 172.28.16.20 db:17
- docker network inspect payments and ip addr show inside db, then test the route back from an approved corporate VM
- Failure signature: using 10.0.0.0/8 out of habit on a host connected to a 10/8 VPN, or reserving the same address in two compose project networks
- Trade-off: Custom addressing integrates legacy routing; stable names and IPAM make general workloads safer and easier to reschedule.
Benchmarks & rules of thumb
- 254 host addresses
- typical /24 pool after network and broadcast
- 172.28.16.1
- example network gateway
- 1 address owner
- Docker IPAM must remain authoritative inside the subnet
Common mistakes & follow-ups
Common interview mistakes
- Treating a successful
docker network create --subnet 172.28.16.0/24 --gateway 172.28.16.1 payments; docker run --network payments --ip 172.28.16.20 db:17as proof and skippingdocker network inspect payments and ip addr show inside db, then test the route back from an approved corporate VM. - Using 10.0.0.0/8 out of habit on a host connected to a 10/8 VPN, or reserving the same address in two compose project networks
- Optimizing Subnet without accepting that custom addressing integrates legacy routing; stable names and IPAM make general workloads safer and easier to reschedule.
Likely interviewer follow-ups
- Why does
docker network create --subnet 172.28.16.0/24 --gateway 172.28.16.1 payments; docker run --network payments --ip 172.28.16.20 db:17address Subnet here rather than through application code? - How would you distinguish healthy Gateway from the failure “using 10.0.0.0/8 out of habit on a host connected to a 10/8 VPN, or reserving the same address in two compose project networks” using
docker network inspect payments and ip addr show inside db, then test the route back from an approved corporate VM? - When would this trade-off-“Custom addressing integrates legacy routing; stable names and IPAM make general workloads safer and easier to reschedule”-justify a different Static IP design?
docker network create --subnet 172.28.16.0/24 --gateway 172.28.16.1 payments; docker run --network payments --ip 172.28.16.20 db:17-and one proof-docker network inspect payments and ip addr show inside db, then test the route back from an approved corporate VM. Then name the boundary: using 10.0.0.0/8 out of habit on a host connected to a 10/8 VPN, or reserving the same address in two compose project networks.Knowledge check
Put it into practice
Practice related interview Q&A
Apply Custom Subnets, Gateways & Static Container IP Assignment with generative AI interview Q&A and hands-on practice.