World map

 

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

Last night's test: one order, then db is removed and started again. psql says relation orders does not exist. Docker transcript: $ docker exec db psql -U postgres -c "select * from orders;" id | dish ----+------------ 1 | nasi lemak (1 row) $ docker rm -f db db $ docker run -d --name db -e POSTGRES_PASSWORD=secret postgres:18-alpine ff26fb60d1866060f2de23803b7bab68ce36c64329453308649d0970d4545128 $ docker exec db psql -U postgres -c "select * from orders" ERROR: relation "orders" does not exist LINE 1: select * from orders ^

Your laptop~

  • No open hatches

Lunchboxes (containers)

  • dbrunning
    from postgres:18-alpine no name → /var/lib/postgresql

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.

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.

Check

The shop app needs to find db. Which setting works?

Swipe right for good, left for needs work. Or use the buttons.

1 / 3DB_HOST=db
DB_HOST=db

Try it

Room 3: start web, the shop page, on shopnet. Open hatch 8080 for customers.

Your laptop~

  • No open hatches

Lunchboxes (containers)

  • dbrunning
    from postgres:18-alpine shopnet pgdata → /var/lib/postgresql

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.

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-alpine

Lunchbox: 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-alpine

Pick 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
    from postgres:18-alpine shopnet pgdata → /var/lib/postgresql
  • webrunning
    from nginx:1.30-alpine 8080→80 shopnet

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.

You did it!

You can now run an app and a database whose data survives.