BM: Baca dalam Bahasa Melayu
World D3: Lockers & Phone Lines
Call containers by name
You will learn: to reach another container by its name, not by localhost.
Checked with Docker Engine 29 on 31 Oct 2026
The problem
Your laptop~
- No open hatches
Lunchboxes (containers)
- menurunning
- cacherunning
Frozen packs (images)
- alpine:3.221 layers · 12.9MB · in use
- nginx:1.30-alpine8 layers · 93.5MB · in use
Phone lines (networks)
- shopnetmenu
2 containers (2 running), 2 images, 0 lockers.
A new box wants the menu, so it asks localhost. Connection refused. Plain words: nobody serves pages inside this box itself.
Watch
Tap each point on the timeline.
On your own line, Docker keeps a phone book. Say a box’s name, get its address. This is container DNS: Docker's phone book on your own network. Say a container's name, get its address..
Try it
From a new box on shopnet, fetch the page at http://menu.
Your laptop~
- No open hatches
Lunchboxes (containers)
- menurunning
- cacherunning
Frozen packs (images)
- alpine:3.221 layers · 12.9MB · in use
- nginx:1.30-alpine8 layers · 93.5MB · in use
Phone lines (networks)
- shopnetmenu
2 containers (2 running), 2 images, 0 lockers.
Hint
The new box must be on shopnet:--network shopnet.Predict
Inside a container, who is localhost?
Pick one answer.
Check
Your laptop~
- No open hatches
Lunchboxes (containers)
- menurunning
- cacherunning
Frozen packs (images)
- alpine:3.221 layers · 12.9MB · in use
- nginx:1.30-alpine8 layers · 93.5MB · in use
Phone lines (networks)
- shopnetmenu
2 containers (2 running), 2 images, 0 lockers.
menu:8080 is refused too. nginx listens on port 80 inside the box. 8080 is only a hatch on your laptop.
Check
An app box talks to db and menu. Good setting, or not?
Swipe right for good, left for needs work. Or use the buttons.
DB_HOST=dbYou did it!
You can now connect containers by name.
Go deeper (optional)
Docker’s phone book lives at 127.0.0.11 inside each box on your own network. --network-alias adds a second name. Compose puts every service on one network and names them for you (World D4).
Real rep (optional):
Real mission
docker network create practice-net && docker run -d --name menu --network practice-net nginx:1.30-alpinedocker run --rm --network practice-net alpine:3.22 wget -qO- http://menudocker run --rm --network practice-net alpine:3.22 wget -qO- http://localhostdocker rm -f menu && docker network rm practice-net
0 of 4 steps done · Your ticks are saved.
Bahasa Melayu
Satu bekas baru mahukan menu, jadi ia tanya localhost. Connection refused. Maksudnya: tiada siapa hidangkan halaman dalam bekas ini sendiri.
Dalam talian sendiri, Docker simpan buku telefon. Sebut nama bekas, dapat alamatnya. Inilah container DNS.
Dari bekas baru di shopnet, ambil halaman di http://menu.
--network shopnet.Dalam satu container, siapa localhost?
menu:8080 pun ditolak. nginx dengar di port 80 dalam bekas. 8080 cuma tingkap di laptop anda.
Satu bekas aplikasi berhubung dengan db dan menu. Tetapan yang baik, atau tidak?
Kini anda boleh sambungkan container ikut nama.
You finished this before. Practice is always welcome!
Official docs: Docker docs: Networking overview (DNS) · Docker docs: Bridge network driver
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?