BM: Baca dalam Bahasa Melayu
World D3: Lockers & Phone Lines · Boss challenge
Data that survives
You will learn: to run an app and Postgres whose data survives docker rm.
Checked with Docker Engine 29 on 31 Oct 2026
The problem
Your laptop~
- No open hatches
Lunchboxes (containers)
- dbrunning
Frozen packs (images)
- postgres:18-alpine9 layers · 433MB · in use
Lockers (volumes)
- 26e7b8e4309c… (no name)24 files · used by db
1 containers (1 running), 1 images, 1 lockers.
Boss: Kedai Kancil opens tomorrow! Last night’s test lost every order. Build it right: a shop and Postgres, with orders that survive docker rm.
Try it
Room 1: make the pgdata locker and the shopnet phone line.
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
- postgres:18-alpine9 layers · 433MB
0 containers (0 running), 3 images, 0 lockers.
Hint
Onedocker volume create, one docker network create.Check
Room 2 starts Postgres 18. Where must the pgdata locker open?
Pick one answer.
Try it
Room 2: start db on shopnet, with the pgdata locker. Then make an orders table.
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
- postgres:18-alpine9 layers · 433MB
Lockers (volumes)
- pgdata0 files
Phone lines (networks)
- shopnet—
0 containers (0 running), 3 images, 1 lockers.
Hint
You need--network shopnet, -e POSTGRES_PASSWORD=… and -v pgdata:/var/lib/postgresql.Check
The shop app needs to find db. Which setting works?
Swipe right for good, left for needs work. Or use the buttons.
DB_HOST=dbTry it
Room 3: start web, the shop page, on shopnet. Open hatch 8080 for customers.
Your laptop~
- No open hatches
Lunchboxes (containers)
- dbrunning
Frozen packs (images)
- alpine:3.221 layers · 12.9MB
- nginx:1.30-alpine8 layers · 93.5MB
- postgres:18-alpine9 layers · 433MB · in use
Lockers (volumes)
- pgdata24 files · used by db
Phone lines (networks)
- shopnetdb
1 containers (1 running), 3 images, 1 lockers.
Hint
web needs both:--network shopnet and -p 8080:80.Predict
Before the last room: a quick locker check. Guess first, then run it.
Where does each file live? Guess what stays, then run it.
$ docker run -d --name kedai -v kedai-data:/data -v ./menu:/menu nginx:1.30-alpineLunchbox: container kedai
- Inside the lunchbox (writable layer)
/app/today.txt
Outside the lunchbox
- Locker kedai-data (volume)
/data/orders.db - Your shelf ./menu (bind mount)
/menu/menu.md
Next, you run:
Throw the container away and start a new one.
$ docker rm -f kedai$ docker run -d --name kedai -v kedai-data:/data -v ./menu:/menu nginx:1.30-alpinePick Stays or Gone for every file first.
Try it
Final room: throw db away with docker rm -f. Start it again on the same line and locker. Then show the orders.
Your laptop~
- Laptop port 8080 → web port 80
Lunchboxes (containers)
- dbrunning
- webrunning
Frozen packs (images)
- alpine:3.221 layers · 12.9MB
- nginx:1.30-alpine8 layers · 93.5MB · in use
- postgres:18-alpine9 layers · 433MB · in use
Lockers (volumes)
- pgdata24 files · used by db
Phone lines (networks)
- shopnetdb ↔ web
2 containers (2 running), 3 images, 1 lockers.
Hint
Use the same run line as Room 2.You did it!
You can now run an app and a database whose data survives.
Bahasa Melayu
Boss: Kedai Kancil buka esok! Ujian semalam hilangkan semua pesanan. Bina dengan betul: kedai dan Postgres, dengan pesanan yang kekal selepas docker rm.
Bilik 1: buat loker pgdata dan talian telefon shopnet.
docker volume create, satu docker network create.Bilik 2 mulakan Postgres 18. Di mana loker pgdata mesti dibuka?
Bilik 2: mulakan db di shopnet, dengan loker pgdata. Kemudian buat jadual orders.
--network shopnet, -e POSTGRES_PASSWORD=… dan -v pgdata:/var/lib/postgresql.Aplikasi kedai perlu cari db. Tetapan mana yang berfungsi?
Bilik 3: mulakan web, halaman kedai, di shopnet. Buka tingkap 8080 untuk pelanggan.
--network shopnet dan -p 8080:80.Sebelum bilik terakhir: semakan loker yang ringkas. Teka dulu, kemudian jalankan.
Bilik terakhir: buang db dengan docker rm -f. Mulakan semula di talian dan loker yang sama. Kemudian tunjuk pesanan.
Kini anda boleh jalankan aplikasi dan pangkalan data yang datanya kekal.
You finished this before. Practice is always welcome!
Official docs: Docker docs: Volumes · Docker docs: Networking overview · Postgres image on Docker Hub
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?