World map

 

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

The page says Kedai Kancil. The file on the laptop now says open today. curl still shows the old page. Docker transcript: $ curl -s localhost:8080 <h1>Kedai Kancil</h1> $ echo "<h1>Kedai Kancil: open today</h1>" > site/index.html $ cat site/index.html <h1>Kedai Kancil: open today</h1> $ curl -s localhost:8080 <h1>Kedai Kancil</h1>

Your laptop~/shop

  • Laptop port 8080 → site port 80

Lunchboxes (containers)

  • siterunning
    from shop-site:1.0 8080→80

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.

Check

site runs with :ro. Something in the box tries to save a file in that folder. What happens?

Pick one answer.

Watch

menu.txt is written to /tmp/cache and read back. After docker restart app, ls says No such file or directory. Docker transcript: $ docker run -d --name app --tmpfs /tmp/cache alpine:3.22 sleep 3600 e19b0f28dc533714dafc8b88863d5ae3b9a6a98cf926514051f4d38a5d83fecf $ docker exec app sh -c "echo hot > /tmp/cache/menu.txt" $ docker exec app cat /tmp/cache/menu.txt hot $ docker restart app app $ docker exec app ls /tmp/cache/menu.txt ls: /tmp/cache/menu.txt: No such file or directory

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

Question 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 kedai

Pick 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

        1. mkdir -p site && echo "<h1>Hello</h1>" > site/index.html
        2. docker run -d --name site -p 8080:80 -v ./site:/usr/share/nginx/html:ro nginx:1.30-alpine
        3. docker rm -f site

        0 of 4 steps done · Your ticks are saved.