BM: Baca dalam Bahasa Melayu
World D3: Lockers & Phone Lines
Publish, expose, host and none
You will learn: which ports your laptop can reach, and the host and none network modes.
Checked with Docker Engine 29 on 31 Oct 2026
The problem
Your laptop~
- No open hatches
Lunchboxes (containers)
- webrunning
Frozen packs (images)
- alpine:3.221 layers · 12.9MB
- nginx:1.30-alpine8 layers · 93.5MB · in use
1 containers (1 running), 2 images, 0 lockers.
web is up. Its PORTS column says 80/tcp. Yet curl says Couldn't connect to server. Plain words: no hatch is open on your laptop.
Watch
Open a hatch from laptop port 8080 to web port 80. Leave db alone.
Tap a laptop port, then a container port.
Your laptop
web
db
$ docker run -d --name web nginx:1.30-alpine$ docker run -d --name db postgres:18-alpineTo publish a port (-p 8080:80) opens a port mapping: The order hatch: a door from a port on your computer to a port in the container. on your laptop. EXPOSE 80 in a recipe only writes the port on the label.
Predict
db shows 5432/tcp, with no -p. Who can reach it?
Pick one answer.
Try it
Give web a hatch on 8080. A box can’t get a new hatch later, so make it again.
Your laptop~
- No open hatches
Lunchboxes (containers)
- webrunning
Frozen packs (images)
- alpine:3.221 layers · 12.9MB
- nginx:1.30-alpine8 layers · 93.5MB · in use
1 containers (1 running), 2 images, 0 lockers.
Hint
Hatches are set when a box is made. Remove web, then run it with-p 8080:80.Watch
Each box gets a line type. The default is bridge. host shares your laptop’s own line. none has no line at all. Sort them.
Drag a card into a box. Or tap the card, then tap the box.
Check
Your laptop~
- No open hatches
Lunchboxes (containers)
- webrunning
Frozen packs (images)
- alpine:3.221 layers · 12.9MB
- nginx:1.30-alpine8 layers · 93.5MB · in use
1 containers (1 running), 2 images, 0 lockers.
Real words from Docker: host mode discards -p. With none, Network unreachable: the box has no line out.
You did it!
You can now choose which ports your laptop can reach.
Go deeper (optional)
-p 8080:80 listens on every network card, so your Wi-Fi neighbours may reach it too. -p 127.0.0.1:8080:80 keeps the hatch for your laptop only. -P opens a random hatch for each exposed port. On Docker Desktop, host mode needs a recent version; check the docs.
Real rep (optional):
Real mission
docker run -d --name web -p 127.0.0.1:8080:80 nginx:1.30-alpinedocker port webdocker run --rm --network none alpine:3.22 ping -c 1 8.8.8.8docker rm -f web
0 of 4 steps done · Your ticks are saved.
Bahasa Melayu
web sedang berjalan. Lajur PORTS tulis 80/tcp. Tapi curl kata Couldn't connect to server. Maksudnya: tiada tingkap dibuka di laptop anda.
Publish port (-p 8080:80) buka tingkap di laptop anda. EXPOSE 80 dalam resepi cuma tulis port itu pada label.
db tunjuk 5432/tcp, tanpa -p. Siapa boleh capai?
Beri web tingkap di 8080. Bekas tak boleh dapat tingkap baru kemudian, jadi buat semula.
-p 8080:80.Setiap bekas ada jenis talian. Yang asal ialah bridge. host kongsi talian laptop anda sendiri. none tiada talian langsung. Susun mereka.
Kata-kata sebenar Docker: mod host buang -p. Dengan none, Network unreachable: bekas itu tiada talian keluar.
Kini anda boleh pilih port mana yang laptop anda boleh capai.
You finished this before. Practice is always welcome!
Official docs: Docker docs: Port publishing · Docker docs: Host network driver · Docker docs: None network driver
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?