Interview's MateDocker
Interview's Mate

Docker

Compose · Networking · Security · Ops

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Docker topics
Lesson 65/ 160
04. Docker Networking

Creating, Inspecting & Connecting Custom Networks (docker network)

Create custom networks and connect/disconnect containers with the network CLI.

Beginnernetwork create · connect3 quiz questions
Practice DevOps Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

In plain words

Declare the network before dependents, label it for ownership and inspect actual endpoint state whenever a policy or route is unclear.

Think of it like…

Network create is laying a road, connect builds a driveway to one house, and inspect shows the address ledger for every junction.

Where you’ve seen it

In practice, docker network create --driver bridge --subnet 172.30.0.0/24 --label owner=platform app-net; docker network connect --alias api app-net api is the concrete move for this job: create custom networks and connect/disconnect containers with the network CLI. The release is not accepted until docker network inspect -f {{json .IPAM.Config}}:{{json .Containers}} app-net and docker port api confirms the result.

Words you’ll hear

network create
The implementation control in docker network create --driver bridge --subnet 172.30.0.0/24 --label owner=platform app-net; docker network connect --alias api app-net api for create custom networks and connect/disconnect containers with the network CLI.
connect
The result to observe with docker network inspect -f {{json .IPAM.Config}}:{{json .Containers}} app-net and docker port api, rather than infer from a successful command alone.
inspect
The production boundary exposed when reusing the corporate VPN’s 10/8 subnet, or creating a network per container and later expecting built-in DNS without attachments.

Visual diagram

Loading interactive diagram

Theory & deep dive

network create control path

The concrete mechanism is docker network create --driver bridge --subnet 172.30.0.0/24 --label owner=platform app-net; docker network connect --alias api app-net api. The observable result is docker network inspect -f {{json .IPAM.Config}}:{{json .Containers}} app-net and docker port api; if those disagree, inspect the runtime evidence before changing unrelated settings.

Create custom networks and connect/disconnect containers with the network CLI. Keep network create, connect and inspect in the same deployment record so the intent and the observed state cannot drift apart.

Concrete network create setup

docker network create --driver bridge --subnet 172.30.0.0/24 --label owner=platform app-net; docker network connect --alias api app-net api

Key takeaway: Prove connect with docker network inspect -f {{json .IPAM.Config}}:{{json .Containers}} app-net and docker port api, not with command success alone.

inspect failure boundary

A duplicate custom subnet can route a local RFC1918 destination into Docker, and disconnecting the last network does not necessarily add the access path the application expected. Network names are daemon-local references. The narrow failure to design for is reusing the corporate VPN’s 10/8 subnet, or creating a network per container and later expecting built-in DNS without attachments.

Accept this compromise explicitly: Explicit networks improve clarity; too many micro-networks require a matrix and gateway approach to keep traffic diagnosable. The controlled check-docker network inspect -f {{json .IPAM.Config}}:{{json .Containers}} app-net and docker port api-also identifies the point where a different design is safer.

Deliberate failure test

Exercise this failure safely: reusing the corporate VPN’s 10/8 subnet, or creating a network per container and later expecting built-in DNS without attachments.

Key takeaway: Explicit networks improve clarity; too many micro-networks require a matrix and gateway approach to keep traffic diagnosable.

How it works, step by step

Step 1 of 4
Design

1. State the boundary

Write down why the workload needs this: A duplicate custom subnet can route a local RFC1918 destination into Docker, and disconnecting the last network does not necessarily add the access path the application expected. Network names are daemon-local references.

Declare the network before dependents, label it for ownership and inspect actual endpoint state whenever a policy or route is unclear.
Key numbers at this step
Intent
network create

When to use it & trade-offs

What it is

docker network create creates a driver-backed address space; connect attaches an existing container endpoint, disconnect removes one, and inspect displays subnets, IPAM, endpoints, gateways and container options. A running container can be attached to more than one Docker network.

Why it matters: A duplicate custom subnet can route a local RFC1918 destination into Docker, and disconnecting the last network does not necessarily add the access path the application expected. Network names are daemon-local references.

When to reach for it

  • The fit is strongest for this job: create custom networks and connect/disconnect containers with the network CLI. Pair it with docker network inspect -f {{json .IPAM.Config}}:{{json .Containers}} app-net and docker port api in the runbook.
  • Production network create changes should make connect observable through docker network create --driver bridge --subnet 172.30.0.0/24 --label owner=platform app-net; docker network connect --alias api app-net api, rather than trusting the runtime default.
  • Keep a rollback example for the case where reusing the corporate VPN’s 10/8 subnet, or creating a network per container and later expecting built-in DNS without attachments.

When to avoid or be careful

  • Do not accept command success while the system can still fail by reusing the corporate VPN’s 10/8 subnet, or creating a network per container and later expecting built-in DNS without attachments.
  • Avoid erasing inspect protection merely to dodge this cost: “Explicit networks improve clarity; too many micro-networks require a matrix and gateway approach to keep traffic diagnosable”.
  • Do not replace the evidence path-docker network inspect -f {{json .IPAM.Config}}:{{json .Containers}} app-net and docker port api-with a screenshot or a mutable tag.

docker network create --driver bridge --subnet 172.30.0.0/24 --label owner=platform app-net; docker network connect --alias api app-net api: practical choices

Explicit network create
Best for: Create custom networks and connect/disconnect containers with the network CLI, with a reviewed runbook.

Strengths: docker network create creates a driver-backed address space; connect attaches an existing container endpoint, disconnect removes one, and inspect displays subnets, IPAM, endpoints, gateways and container options. A running container can be attached to more than one Docker network.

Watch out: Explicit networks improve clarity; too many micro-networks require a matrix and gateway approach to keep traffic diagnosable.

Ambient default
Best for: Short-lived connect experiments with low blast radius.

Strengths: It can begin with docker network create --driver bridge --subnet 172.30.0.0/24 --label owner=platform app-net; docker network connect --alias api app-net api and fewer surrounding controls.

Watch out: It silently accepts reusing the corporate VPN’s 10/8 subnet, or creating a network per container and later expecting built-in DNS without attachments, which makes the result hard to reproduce after promotion.

Managed inspect
Best for: Teams that centralize inspect policy across many workloads.

Strengths: A duplicate custom subnet can route a local RFC1918 destination into Docker, and disconnecting the last network does not necessarily add the access path the application expected. Network names are daemon-local references.

Watch out: The platform adds an ownership and debugging layer; retain docker network inspect -f {{json .IPAM.Config}}:{{json .Containers}} app-net and docker port api as the direct check.

Interview signals & numbers to know

When this topic comes up

  • docker network create --driver bridge --subnet 172.30.0.0/24 --label owner=platform app-net; docker network connect --alias api app-net api
  • docker network inspect -f {{json .IPAM.Config}}:{{json .Containers}} app-net and docker port api
  • Failure signature: reusing the corporate VPN’s 10/8 subnet, or creating a network per container and later expecting built-in DNS without attachments
  • Trade-off: Explicit networks improve clarity; too many micro-networks require a matrix and gateway approach to keep traffic diagnosable.

Benchmarks & rules of thumb

172.30.0.0/24 -
256-address example subnet
1 gateway -
normally reserved from the address pool
2 operations -
connect and disconnect can change the peer route set live

Common mistakes & follow-ups

Common interview mistakes

  • Treating a successful docker network create --driver bridge --subnet 172.30.0.0/24 --label owner=platform app-net; docker network connect --alias api app-net api as proof and skipping docker network inspect -f {{json .IPAM.Config}}:{{json .Containers}} app-net and docker port api.
  • Reusing the corporate VPN’s 10/8 subnet, or creating a network per container and later expecting built-in DNS without attachments
  • Optimizing network create without accepting that explicit networks improve clarity; too many micro-networks require a matrix and gateway approach to keep traffic diagnosable.

Likely interviewer follow-ups

  • Why does docker network create --driver bridge --subnet 172.30.0.0/24 --label owner=platform app-net; docker network connect --alias api app-net api address network create here rather than through application code?
  • How would you distinguish healthy connect from the failure “reusing the corporate VPN’s 10/8 subnet, or creating a network per container and later expecting built-in DNS without attachments” using docker network inspect -f {{json .IPAM.Config}}:{{json .Containers}} app-net and docker port api?
  • When would this trade-off-“Explicit networks improve clarity; too many micro-networks require a matrix and gateway approach to keep traffic diagnosable”-justify a different inspect design?
Interview tip: Give one concrete operation-docker network create --driver bridge --subnet 172.30.0.0/24 --label owner=platform app-net; docker network connect --alias api app-net api-and one proof-docker network inspect -f {{json .IPAM.Config}}:{{json .Containers}} app-net and docker port api. Then name the boundary: reusing the corporate VPN’s 10/8 subnet, or creating a network per container and later expecting built-in DNS without attachments.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Creating, Inspecting & Connecting Custom Networks (docker network) with generative AI interview Q&A and hands-on practice.

Open DevOps Q&A →Tech Learn Q&A
Previous topic
Built-in Docker DNS & Automatic Service Discovery by Container Name
Next topic
Container-to-Container Communication Across Isolated Networks