World map

 

BM: Baca dalam Bahasa Melayu

World D3: Lockers & Phone Lines

Where did my data go?

You will learn: why files saved inside a container vanish.

Checked with Docker Engine 29 on 31 Oct 2026

The problem

orders.txt says nasi lemak. Aina removes the container kedai and starts a new one. Now ls says No such file or directory. Docker transcript: $ docker exec kedai cat /orders.txt nasi lemak $ docker rm -f kedai kedai $ docker run -d --name kedai nginx:1.30-alpine a5e8d729798055e459d37f5d9d4c49d4ed56e791fffee5ef328300b2c132960f $ docker exec kedai ls /orders.txt ls: /orders.txt: No such file or directory

Your laptop~

  • No open hatches

Lunchboxes (containers)

  • kedairunning
    from nginx:1.30-alpine

Frozen packs (images)

  • alpine:3.221 layers · 12.9MB
  • nginx:1.30-alpine8 layers · 93.5MB · in use

1 containers (1 running), 2 images, 0 lockers.

Aina kept today’s orders inside her container. Then she swapped it for a fresh one. The orders vanished. Where did they go?

Watch

Tap each point on the timeline.

Every container gets its own thin top layer. This is the writable layer: The container's own thin top layer. Your changes land there. docker rm throws it away.. Tap each step to follow orders.txt.

Try it

Restart kedai. Then check that orders.txt is still there.

Your laptop~

  • No open hatches

Lunchboxes (containers)

  • kedairunning
    from nginx:1.30-alpine

Frozen packs (images)

  • alpine:3.221 layers · 12.9MB
  • nginx:1.30-alpine8 layers · 93.5MB · in use

1 containers (1 running), 2 images, 0 lockers.

Predict

Guess first, then run it. Does the file survive?

Where does each file live? Guess what stays, then run it.

$ docker run -d --name kedai nginx:1.30-alpine

Question 1 of 2

Lunchbox: container kedai

  • Inside the lunchbox (writable layer)/app/orders.txt

Outside the lunchbox

    Next, you run:

    Restart the container.

    $ docker restart kedai

    Pick Stays or Gone for every file first.

    Check

    After docker rm, what is gone and what stays?

    Drag a card into a box. Or tap the card, then tap the box.

        Check

        Your shop app saves photo uploads in /app/uploads. How do you keep them safe?

        Pick one answer.

        You did it!

        You can now explain why files inside a container vanish.

        Go deeper (optional)

        docker diff lists what changed in the writable layer. A means added, C changed, D deleted.

        bash
        docker run -d --name box alpine:3.22 sleep 600
        docker exec box sh -c "echo nasi lemak > /orders.txt"
        docker diff box
        A /orders.txt
        docker diff on a fresh alpine container shows one added file: A /orders.txt.

        Real rep (optional), on your own Docker or in Codespaces:

        Real mission

        1. docker run -d --name box alpine:3.22 sleep 600
        2. docker exec box sh -c "echo hi > /note.txt"
        3. docker rm -f box
        4. docker run --rm alpine:3.22 cat /note.txt

        0 of 4 steps done · Your ticks are saved.