Guides
Docker Networking: Bridge, Host आणि Custom Networks
By Ravindra Bagale, DevOps trainer · LinkedIn · Published: · Last updated:
Custom bridge, नावाने बोला, -p, stacks isolate.
Friends, default bridge is fine for one box demos; custom networks give DNS names. Chala mitrano — name your network.
मित्रांनो, default bridge demos साठी ठीक; custom networks DNS नावे देतात. Chala mitrano — network ला नाव द्या.
मित्रों, default bridge demos के लिए ठीक; custom networks DNS नाम देते हैं। Chala mitrano — network को नाम दें।
Quick answer
Hold this vertical picture:
- Networks यादी.
- Custom तयार.
- api+db.
- -p.
- Isolate.
Language: English · मराठी · हिंदी
Docker networks
Networks का
नावाने सापडत नसलेले containers Compose मध्ये गोंधळ.
Why: स्थिर DNS आणि isolation.
What: bridge/host/custom/-p.
How: labnet तयार करा.
Example 1: List networks
Type this:
command -v docker >/dev/null && docker network ls || printf "%s\n" "NETWORK ID NAME DRIVER\n... bridge bridge\n... host host\n... none null"
You will see:
NETWORK ID NAME DRIVER
... bridge bridge
... host host
... none null
What it means: Every Docker engine starts with bridge, host, and none.
Example 2: Create a custom bridge
Type this:
command -v docker >/dev/null && docker network create labnet || printf "%s\n" "labnet"
You will see:
What it means: User-defined bridges provide automatic DNS between containers.
Example 3: Inspect the network
Type this:
command -v docker >/dev/null && docker network inspect labnet --format "{{.Name}} {{.Driver}}" || printf "%s\n" "labnet bridge"
You will see:
What it means: Driver bridge is the usual choice for multi-container apps on one host.
Concept 1: Custom DNS
User-defined bridge नावे resolve करते.
Why: api→db hostname.
What: --network; Compose
How: Multi-service साठी.
Example 4: Attach by name (sketch)
Type this:
printf "%s\n" "docker run -d --name db --network labnet redis:7" "docker run -d --name api --network labnet myapi:1"
You will see:
docker run -d --name db --network labnet redis:7
docker run -d --name api --network labnet myapi:1
What it means: api can resolve host db on labnet.
Example 7: Compose networks
Type this:
printf "%s\n" "services:" " api:" " networks: [appnet]" " db:" " networks: [appnet]" "networks:" " appnet:"
You will see:
services:
api:
networks: [appnet]
db:
networks: [appnet]
networks:
appnet:
What it means: Compose creates the user-defined network for you.
Example 8: DNS test sketch
Type this:
printf "%s\n" "docker exec api ping -c1 db"
You will see:
docker exec api ping -c1 db
What it means: Name db works on custom networks; often fails on legacy default bridge without links.
Concept 2: Publish/host
-p लोकांसाठी; host mode दुर्मिळ.
Why: काळजीपूर्वक expose.
What: -p; ss
How: Conflict तपासा.
Example 5: Publish a port
Type this:
printf "%s\n" "docker run -d -p 8080:80 --name web nginx:alpine"
You will see:
docker run -d -p 8080:80 --name web nginx:alpine
What it means: -p host:container maps traffic into the container.
Example 6: Host network note
Type this:
printf "%s\n" "docker run --network host ... shares the host network namespace"
You will see:
docker run --network host ... shares the host network namespace
What it means: Useful for special cases; skips isolation — rare in shared EC2 labs.
Example 11: Port conflict tip
Type this:
printf "%s\n" "Bind for 0.0.0.0:8080 failed = something else uses 8080" "ss -lntp | grep 8080"
You will see:
Bind for 0.0.0.0:8080 failed = something else uses 8080
ss -lntp | grep 8080
What it means: Check the host before changing the app.
Concept 3: Isolate
एक app एक network.
Why: Blast radius कमी.
What: connect/disconnect
How: Network card.
Example 9: Isolate two stacks
Type this:
printf "%s\n" "app1net for shop" "app2net for blog" "Do not share unless needed"
You will see:
app1net for shop
app2net for blog
Do not share unless needed
What it means: Isolation reduces blast radius — Accenture security reviews like this.
Example 10: Disconnect / connect
Type this:
printf "%s\n" "docker network connect labnet api" "docker network disconnect labnet api"
You will see:
docker network connect labnet api
docker network disconnect labnet api
What it means: Move running containers between networks when needed.
Example 12: Network card
Type this:
printf "%s\n" "1 custom bridge 2 same network names 3 -p for humans 4 isolate stacks"
You will see:
1 custom bridge 2 same network names 3 -p for humans 4 isolate stacks
What it means: Memorize for Docker networking interviews.
Network card
1 custom bridge 2 api+db 3 -p 4 isolate
Suppose: Shop Compose
appnet.
Suppose: Port busy
ss; दुसरा port.
Ravindra Bagale's Tip
Compose on Flipkart labs puts api and db on one user-defined bridge so api talks to db by hostname.
Flipkart labs च्या Compose मध्ये api आणि db एका user-defined bridge वर — hostname ने बोलतात.
Flipkart labs के Compose में api और db एक user-defined bridge पर — hostname से बात करते हैं।
Check yourself (quiz)
Q1. Custom bridge?
DNS नावे
Q2. -p?
host:container
Q3. Host net?
कमी isolation
Q4. Compose?
networks:
Q5. Port busy?
ss -lntp
Q6. Isolate?
वेगळी networks
Reading tracking
Mark this guide when you finish. Your browser remembers it on this device.
Custom → DNS → publish → isolate.
Did you understand? Let us try it once more.
Frequently asked questions
Why custom bridge?
Automatic DNS between names.
What does -p do?
Maps hostPort to containerPort.
When host network?
Rare special cases; less isolation.
Compose networks?
Declare networks and attach services.
Port in use?
Check ss -lntp; change host port.
Isolate how?
One user-defined network per stack.