C.W.K.
Stream
Lesson 01 of 04 · published

Custom Networks — DNS by Service Name

~14 min · networking

Level 0Container Curious
0 XP0/36 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

The default bridge has a critical gap

Containers on Docker's default bridge network can talk to each other only by IP — and IPs change on restart. There is no DNS resolution between containers on the default bridge.

Custom bridge networks fix this

On a custom bridge network, Docker runs an embedded DNS server (at 127.0.0.11 inside containers). Containers resolve each other by container name. curl http://api:8000 just works.

This is why every multi-container setup beyond "two test containers" should use a custom network.

Code

DNS-by-name on a custom network·bash
docker network create app-net

# Two containers on the same custom network
docker run -d --name api --network app-net myapi:1.0
docker run -d --name web --network app-net -p 3000:3000 myweb:1.0

# From inside web, reach api by name
docker exec web curl http://api:8000/health
# ← works because Docker's embedded DNS resolves 'api'
Multiple networks for tiered isolation·bash
docker network create frontend-net
docker network create backend-net

# Web sees only frontend
docker run -d --name web --network frontend-net -p 80:80 nginx

# API straddles both — bridge between web and db
docker run -d --name api --network frontend-net myapi
docker network connect backend-net api

# DB is only on backend (web cannot reach it)
docker run -d --name db --network backend-net postgres:16

# Result:
#   web → api  ✓ (frontend-net)
#   api → db   ✓ (backend-net)
#   web → db   ✗ (different networks, isolated)

External links

Exercise

Build the tiered network example above. From web, verify you can reach api but NOT db. From api, verify you can reach both. Capture the curl results.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.