BM: Baca dalam Bahasa Melayu
World D1: First Containers
Handy run flags: -d, --name, --rm
You will learn: to run a container in the background, give it a name, and let it tidy up.
Checked with Docker Engine 29 on 31 Oct 2026
The problem
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.
You ran nginx. Now your terminal is stuck, full of messages. And the box got a random name. Let’s fix both.
Try it
Build a better command. detached (-d): The container runs in the background, like a rice cooker: press start, walk away. means detached. The box runs in the background, like a rice cooker. --name picks its name.
Tap the pieces in the right order.
Try it
Now type it. Your terminal stays free, and the box is called web.
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.
Hint
docker run -d --name web nginx:1.30-alpineWatch
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.
–rm throws the box away when its job ends. docker ps -a shows nothing left. Perfect for one-off jobs.
Try it
Which flag fits each job?
Drag a card into a box. Or tap the card, then tap the box.
Predict
web already exists. You run docker run -d --name web nginx:1.30-alpine again. 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 says the name "/web" is already in use. Plain words: one name, one box. Remove the old box, or pick a new name.
You did it!
You can now run, name and tidy up boxes with three flags.
Go deeper (optional)
-d and --rm work together: a background box that cleans up when it stops. docker rename web shop changes a name. -it gives you a keyboard inside a box; that comes in lesson 6.
Real rep (optional):
Real mission
docker run -d --name web nginx:1.30-alpinedocker run --rm alpine:3.22 echo hidocker ps -adocker rm -f web
0 of 4 steps done · Your ticks are saved.
Bahasa Melayu
Anda jalankan nginx. Kini terminal anda tersekat, penuh dengan mesej. Bekas itu pula dapat nama rawak. Jom baiki kedua-duanya.
Bina arahan yang lebih baik. -d bermaksud detached. Bekas berjalan di belakang, macam periuk nasi. --name pilih namanya.
Sekarang taip. Terminal anda tetap bebas, dan bekas itu bernama web.
docker run -d --name web nginx:1.30-alpine–rm buang bekas bila kerjanya selesai. docker ps -a tunjuk tiada apa yang tinggal. Sesuai untuk kerja sekali jalan.
Pilihan mana sesuai untuk setiap kerja?
web sudah wujud. Anda jalankan docker run -d --name web nginx:1.30-alpine sekali lagi. Apa jadi?
Ralat sebenar kata nama "/web" is already in use. Maksudnya: satu nama, satu bekas. Buang bekas lama, atau pilih nama baru.
Kini anda boleh jalan, namakan dan kemas bekas dengan tiga pilihan.
You finished this before. Practice is always welcome!
Official docs: docker run · Overriding container defaults
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?