BM: Baca dalam Bahasa Melayu
World D1: First Containers
Settings with -e
You will learn: to hand a container its settings with -e, and to read what it asks for.
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
- postgres:18-alpine9 layers · 433MB
0 containers (0 running), 2 images, 0 lockers.
You start a database box, db. A second later it says Exited (1). Something is missing. But what?
Try it
Ask db why. Read its logs.
Your laptop~
- No open hatches
Lunchboxes (containers)
- dbfailed (exit 1)
Frozen packs (images)
- alpine:3.221 layers · 12.9MB
- postgres:18-alpine9 layers · 433MB · in use
Lockers (volumes)
- 618a61fe96bb… (no name)0 files · used by db
1 containers (0 running), 2 images, 1 lockers.
Hint
Typedocker logs db.Watch
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.
-e sticks a note on the lunchbox lid. The note is an environment variable: NAME=Aina sets NAME to Aina. The app inside reads it.
Try it
Build the command that gives db its password.
Tap the pieces in the right order.
Try it
Fix db. Remove the broken box. Then start a new one with a password.
Your laptop~
- No open hatches
Lunchboxes (containers)
- dbfailed (exit 1)
Frozen packs (images)
- alpine:3.221 layers · 12.9MB
- postgres:18-alpine9 layers · 433MB · in use
Lockers (volumes)
- 618a61fe96bb… (no name)0 files · used by db
1 containers (0 running), 2 images, 1 lockers.
Predict
You gave db -e POSTGRES_PASSWORD=secret. Does the postgres meal pack change?
Pick one answer.
Check
Will Postgres find its password? Swipe each one.
Swipe right for good, left for needs work. Or use the buttons.
-e POSTGRES_PASSWORD=secretYou did it!
You can now hand a container its settings with -e.
Go deeper (optional)
docker inspect -f '{{.Config.Env}}' db lists every note on a box. Anyone who can run Docker can read them. So keep real passwords out of -e on shared machines. World D3 shows safer ways. -e NAME with no value copies NAME from your laptop.
Real rep (optional):
Real mission
docker run --rm -e NAME=you alpine:3.22 printenv NAMEdocker run -d --name db -e POSTGRES_PASSWORD=secret postgres:18-alpinedocker logs dbdocker rm -f db
0 of 4 steps done · Your ticks are saved.
Bahasa Melayu
Anda mulakan bekas pangkalan data, db. Sesaat kemudian ia kata Exited (1). Ada sesuatu yang tertinggal. Tapi apa?
Tanya db kenapa. Baca lognya.
docker logs db.-e lekatkan nota pada penutup bekas. Nota itu ialah environment variable (pemboleh ubah persekitaran): NAME=Aina tetapkan NAME kepada Aina. Aplikasi di dalam membacanya.
Bina arahan yang beri db kata laluannya.
Baiki db. Buang bekas yang rosak. Kemudian mulakan yang baru dengan kata laluan.
Anda beri db -e POSTGRES_PASSWORD=secret. Adakah pek beku postgres berubah?
Adakah Postgres jumpa kata laluannya? Leret setiap satu.
Kini anda boleh beri container tetapannya dengan -e.
You finished this before. Practice is always welcome!
Official docs: docker run: set environment variables · Overriding container defaults
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?