BM: Baca dalam Bahasa Melayu
World D3: Lockers & Phone Lines
Bind mounts and tmpfs
You will learn: to share a laptop folder with a container, and to keep data in memory only.
Checked with Docker Engine 29 on 31 Oct 2026
The problem
Your laptop~/shop
- Laptop port 8080 → site port 80
Lunchboxes (containers)
- siterunning
Frozen packs (images)
- nginx:1.30-alpine8 layers · 93.5MB
- shop-site:1.09 layers · 92.6MB · in use
1 containers (1 running), 2 images, 0 lockers.
You fixed the shop page on your laptop. The box still shows the old page. It was baked into the image. Rebuild for every typo?
Watch
A bind mount: Your own shelf: a folder on your laptop, opened inside the container. Edits show up at once. slides your own shelf into the lunchbox. The box sees your laptop folder itself, not a copy. Tap the pieces in order.
Tap the pieces in the right order.
Try it
Run site with your ./site shelf. Then change index.html and curl again.
Your laptop~/shop
- 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
The folder needs./ in front: -v ./site:/usr/share/nginx/html:ro.Check
site runs with :ro. Something in the box tries to save a file in that folder. What happens?
Pick one answer.
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
- postgres:18-alpine9 layers · 433MB
0 containers (0 running), 3 images, 0 lockers.
tmpfs: A note on a whiteboard: data kept in memory only. Every stop wipes it. is a note on a whiteboard: memory only. It is fast and never touches the disk. Every stop wipes it.
Predict
Four places to keep a file. 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 --tmpfs /tmp/cache nginx:1.30-alpineQuestion 1 of 2
Lunchbox: container kedai
- Inside the lunchbox (writable layer)
/app/today.txt - A note in memory (tmpfs)
/tmp/cache/cache.bin
Outside the lunchbox
- Locker kedai-data (volume)
/data/orders.db - Your shelf ./menu (bind mount)
/menu/menu.md
Next, you run:
Restart the container.
$ docker restart kedaiPick Stays or Gone for every file first.
Check
Pick the right place for each job.
Drag a card into a box. Or tap the card, then tap the box.
You did it!
You can now use bind mounts and tmpfs.
Go deeper (optional)
--mount type=bind,src=./site,dst=/data is the long form. It refuses a folder that doesn’t exist; -v quietly makes an empty one. On Docker Desktop, volumes are faster than bind mounts.
Real rep (optional), in your own project folder:
Real mission
mkdir -p site && echo "<h1>Hello</h1>" > site/index.htmldocker run -d --name site -p 8080:80 -v ./site:/usr/share/nginx/html:ro nginx:1.30-alpinedocker rm -f site
0 of 4 steps done · Your ticks are saved.
Bahasa Melayu
Anda dah baiki halaman kedai di laptop. Bekas masih tunjuk halaman lama. Ia dah dibakar dalam image. Nak bina semula untuk setiap salah taip?
Bind mount (rak sendiri) sorong rak anda masuk ke bekas. Bekas nampak folder laptop itu sendiri, bukan salinan. Tekan kepingan ikut urutan.
Jalankan site dengan rak ./site anda. Kemudian ubah index.html dan curl sekali lagi.
./ di depan: -v ./site:/usr/share/nginx/html:ro.site berjalan dengan :ro. Sesuatu dalam bekas cuba simpan fail dalam folder itu. Apa jadi?
tmpfs ialah nota di papan putih: dalam memori sahaja. Ia laju dan tak pernah sentuh cakera. Setiap kali berhenti, ia dipadam.
Empat tempat untuk simpan fail. Teka dulu, kemudian jalankan.
Pilih tempat yang betul untuk setiap kerja.
Kini anda boleh guna bind mount dan tmpfs.
You finished this before. Practice is always welcome!
Official docs: Docker docs: Bind mounts · Docker docs: tmpfs mounts
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?