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 63/ 160
04. Docker Networking

Default Bridge vs User-Defined Bridge Networks

Prefer user-defined bridges for DNS-based service discovery between containers.

BeginnerDefault Bridge · User-Defined3 quiz questions
Practice DevOps Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

In plain words

Create a user-defined bridge for each application boundary so services use stable names and remain isolated from unrelated containers.

Think of it like…

The default bridge is a shared lobby with seat numbers; a user-defined bridge is a meeting room with a nameplate directory.

Where you’ve seen it

In practice, docker network create shop; docker run -d --name db --network shop postgres:17; docker run --rm --network shop alpine:3.21 nslookup db is the concrete move for this job: prefer user-defined bridges for DNS-based service discovery between containers. The release is not accepted until disconnect db from shop and observe DNS/connection failure without changing the database IP configuration confirms the result.

Words you’ll hear

Default Bridge
The implementation control in docker network create shop; docker run -d --name db --network shop postgres:17; docker run --rm --network shop alpine:3.21 nslookup db for prefer user-defined bridges for DNS-based service discovery between containers.
User-Defined
The result to observe with disconnect db from shop and observe DNS/connection failure without changing the database IP configuration, rather than infer from a successful command alone.
DNS
The production boundary exposed when using --link as a modern service-discovery strategy, or resolving a service that is attached to a different user-defined bridge.

Visual diagram

Loading interactive diagram

Theory & deep dive

Default Bridge control path

The concrete mechanism is docker network create shop; docker run -d --name db --network shop postgres:17; docker run --rm --network shop alpine:3.21 nslookup db. The observable result is disconnect db from shop and observe DNS/connection failure without changing the database IP configuration; if those disagree, inspect the runtime evidence before changing unrelated settings.

Prefer user-defined bridges for DNS-based service discovery between containers. Keep Default Bridge, User-Defined and DNS in the same deployment record so the intent and the observed state cannot drift apart.

Concrete Default Bridge setup

docker network create shop; docker run -d --name db --network shop postgres:17; docker run --rm --network shop alpine:3.21 nslookup db

Key takeaway: Prove User-Defined with disconnect db from shop and observe DNS/connection failure without changing the database IP configuration, not with command success alone.

DNS failure boundary

Relying on IP addresses breaks as containers are recreated. On a custom bridge a container name or network alias can resolve, but DNS works only for peers attached to the same network-not through the Docker default bridge. The narrow failure to design for is using --link as a modern service-discovery strategy, or resolving a service that is attached to a different user-defined bridge.

Accept this compromise explicitly: User-defined bridges improve DNS and isolation; each additional network requires explicit attachment and dependency reasoning. The controlled check-disconnect db from shop and observe DNS/connection failure without changing the database IP configuration-also identifies the point where a different design is safer.

Deliberate failure test

Exercise this failure safely: using --link as a modern service-discovery strategy, or resolving a service that is attached to a different user-defined bridge.

Key takeaway: User-defined bridges improve DNS and isolation; each additional network requires explicit attachment and dependency reasoning.

How it works, step by step

Step 1 of 4
Design

1. State the boundary

Write down why the workload needs this: Relying on IP addresses breaks as containers are recreated. On a custom bridge a container name or network alias can resolve, but DNS works only for peers attached to the same network-not through the Docker default bridge.

Create a user-defined bridge for each application boundary so services use stable names and remain isolated from unrelated containers.
Key numbers at this step
Intent
Default Bridge

When to use it & trade-offs

What it is

The legacy docker0 bridge gives containers egress and supports published ports but requires legacy links or IPs for many peer-discovery workflows. A user-defined bridge provides embedded DNS, automatic per-container DNS updates and explicit membership.

Why it matters: Relying on IP addresses breaks as containers are recreated. On a custom bridge a container name or network alias can resolve, but DNS works only for peers attached to the same network-not through the Docker default bridge.

When to reach for it

  • The fit is strongest for this job: prefer user-defined bridges for DNS-based service discovery between containers. Pair it with disconnect db from shop and observe DNS/connection failure without changing the database IP configuration in the runbook.
  • Production Default Bridge changes should make User-Defined observable through docker network create shop; docker run -d --name db --network shop postgres:17; docker run --rm --network shop alpine:3.21 nslookup db, rather than trusting the runtime default.
  • Keep a rollback example for the case where using --link as a modern service-discovery strategy, or resolving a service that is attached to a different user-defined bridge.

When to avoid or be careful

  • Do not accept command success while the system can still fail by using --link as a modern service-discovery strategy, or resolving a service that is attached to a different user-defined bridge.
  • Avoid erasing DNS protection merely to dodge this cost: “User-defined bridges improve DNS and isolation; each additional network requires explicit attachment and dependency reasoning”.
  • Do not replace the evidence path-disconnect db from shop and observe DNS/connection failure without changing the database IP configuration-with a screenshot or a mutable tag.

docker network create shop; docker run -d --name db --network shop postgres:17; docker run --rm --network shop alpine:3.21 nslookup db: practical choices

Explicit Default Bridge
Best for: Prefer user-defined bridges for DNS-based service discovery between containers, with a reviewed runbook.

Strengths: The legacy docker0 bridge gives containers egress and supports published ports but requires legacy links or IPs for many peer-discovery workflows. A user-defined bridge provides embedded DNS, automatic per-container DNS updates and explicit membership.

Watch out: User-defined bridges improve DNS and isolation; each additional network requires explicit attachment and dependency reasoning.

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

Strengths: It can begin with docker network create shop; docker run -d --name db --network shop postgres:17; docker run --rm --network shop alpine:3.21 nslookup db and fewer surrounding controls.

Watch out: It silently accepts using --link as a modern service-discovery strategy, or resolving a service that is attached to a different user-defined bridge, which makes the result hard to reproduce after promotion.

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

Strengths: Relying on IP addresses breaks as containers are recreated. On a custom bridge a container name or network alias can resolve, but DNS works only for peers attached to the same network-not through the Docker default bridge.

Watch out: The platform adds an ownership and debugging layer; retain disconnect db from shop and observe DNS/connection failure without changing the database IP configuration as the direct check.

Interview signals & numbers to know

When this topic comes up

  • docker network create shop; docker run -d --name db --network shop postgres:17; docker run --rm --network shop alpine:3.21 nslookup db
  • disconnect db from shop and observe DNS/connection failure without changing the database IP configuration
  • Failure signature: using --link as a modern service-discovery strategy, or resolving a service that is attached to a different user-defined bridge
  • Trade-off: User-defined bridges improve DNS and isolation; each additional network requires explicit attachment and dependency reasoning.

Benchmarks & rules of thumb

127.0.0.11 -
Docker embedded DNS address inside a user-defined network
1 Docker host -
scope of a bridge network
0 stable IP guarantees -
for ordinary recreated containers

Common mistakes & follow-ups

Common interview mistakes

  • Treating a successful docker network create shop; docker run -d --name db --network shop postgres:17; docker run --rm --network shop alpine:3.21 nslookup db as proof and skipping disconnect db from shop and observe DNS/connection failure without changing the database IP configuration.
  • Using --link as a modern service-discovery strategy, or resolving a service that is attached to a different user-defined bridge
  • Optimizing Default Bridge without accepting that user-defined bridges improve DNS and isolation; each additional network requires explicit attachment and dependency reasoning.

Likely interviewer follow-ups

  • Why does docker network create shop; docker run -d --name db --network shop postgres:17; docker run --rm --network shop alpine:3.21 nslookup db address Default Bridge here rather than through application code?
  • How would you distinguish healthy User-Defined from the failure “using --link as a modern service-discovery strategy, or resolving a service that is attached to a different user-defined bridge” using disconnect db from shop and observe DNS/connection failure without changing the database IP configuration?
  • When would this trade-off-“User-defined bridges improve DNS and isolation; each additional network requires explicit attachment and dependency reasoning”-justify a different DNS design?
Interview tip: Give one concrete operation-docker network create shop; docker run -d --name db --network shop postgres:17; docker run --rm --network shop alpine:3.21 nslookup db-and one proof-disconnect db from shop and observe DNS/connection failure without changing the database IP configuration. Then name the boundary: using --link as a modern service-discovery strategy, or resolving a service that is attached to a different user-defined bridge.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Default Bridge vs User-Defined Bridge Networks with generative AI interview Q&A and hands-on practice.

Open DevOps Q&A →Tech Learn Q&A
Previous topic
Default Docker Networks (bridge, host, none)
Next topic
Built-in Docker DNS & Automatic Service Discovery by Container Name