BM: Baca dalam Bahasa Melayu
World D1: First Containers
The order hatch: port mapping
You will learn: to open a door from your laptop into a container with -p.
Checked with Docker Engine 29 on 31 Oct 2026
The problem
Your laptop~
- No open hatches
Lunchboxes (containers)
- webrunning
Frozen packs (images)
- nginx:1.30-alpine8 layers · 93.5MB · in use
1 containers (1 running), 1 images, 0 lockers.
web is Up, but the real error says Couldn't connect to server. Plain words: nobody answers at port 8080 on your laptop. The box is sealed.
Try it
Cut an order hatch: plug laptop port 8080 into web’s port 80. This is port mapping: The order hatch: a door from a port on your computer to a port in the container..
Open the order hatch: laptop port 8080 to web port 80.
Tap a laptop port, then a container port.
Your laptop
web
$ docker run -d --name web nginx:1.30-alpineWatch
Your laptop~
- No open hatches
Lunchboxes (containers)
- webrunning
Frozen packs (images)
- nginx:1.30-alpine8 layers · 93.5MB · in use
1 containers (1 running), 1 images, 0 lockers.
A hatch is cut when a box is made. So web is made again. Read -p 8080:80 left to right: laptop first, box second.
Try it
Your turn. Run web with a hatch on 8080. Then curl localhost:8080.
Your laptop~
- No open hatches
Lunchboxes (containers)
- No containers yet
Frozen packs (images)
- alpine:3.221 layers · 12.9MB
- nginx:1.30-alpine8 layers · 93.5MB
0 containers (0 running), 2 images, 0 lockers.
Predict
web holds hatch 8080. A new box, api, also asks for laptop port 8080. What happens?
Pick one answer.
Check
Your laptop~
- Laptop port 8080 → web port 80
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.
The real error ends with port is already allocated. Plain words: another box already uses laptop port 8080.
Try it
Give api its own hatch. Any free laptop port works.
api needs a hatch too. 8080 is busy.
Tap a laptop port, then a container port.
Your laptop
web
api
-p 8080:80laptop 8080 → web:80
$ docker run -d --name web -p 8080:80 nginx:1.30-alpine$ docker run -d --name api nginx:1.30-alpineCheck
docker run -d -p 3000:80 nginx:1.30-alpine. Which address opens the page?
Pick one answer.
You did it!
You can now open an order hatch into a container.
Go deeper (optional)
Without an address, -p opens the hatch on every network you are on. Others on your Wi-Fi may reach it! -p 127.0.0.1:8080:80 keeps it for your laptop only. More hatch tricks come in World D3.
Real rep (optional):
Real mission
docker run -d --name web -p 127.0.0.1:8080:80 nginx:1.30-alpinedocker port webdocker rm -f web
0 of 4 steps done · Your ticks are saved.
Bahasa Melayu
web Up, tapi ralat sebenar kata Couldn't connect to server. Maksudnya: tiada siapa jawab di port 8080 laptop anda. Bekas itu bertutup.
Buka tingkap pesanan: sambung port laptop 8080 ke port 80 web. Inilah port mapping.
Tingkap dibuka semasa bekas dibuat, jadi web dibuat semula. Baca -p 8080:80 dari kiri: laptop dulu, bekas kemudian.
Giliran anda. Jalankan web dengan tingkap di 8080. Kemudian curl localhost:8080.
web pegang tingkap 8080. Bekas baru, api, juga minta port laptop 8080. Apa jadi?
Ralat sebenar berakhir dengan port is already allocated. Maksudnya: bekas lain sudah guna port laptop 8080.
Beri api tingkapnya sendiri. Mana-mana port laptop yang kosong boleh.
docker run -d -p 3000:80 nginx:1.30-alpine. Alamat mana yang buka halaman itu?
Kini anda boleh buka tingkap pesanan ke dalam container.
You finished this before. Practice is always welcome!
Official docs: Port publishing and mapping · Publishing and exposing ports · docker port
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?