Docker writable layers: what happens to files?
Lab prerequisites
Use only an approved disposable, offline Linux VM with a local Docker Engine, ordinary local volume driver, and reviewed preloaded busybox:1.37 (record its digest, platform, exact Engine version and required utilities first). Verify the active Docker context and endpoint; every bm-v06 resource name in the lesson must be unused before starting. Never reuse a pre-existing volume. Use a dedicated lab shell, run commands individually in order, and stop on unexpected errors (the explicitly labeled negative tests are exceptions). Only delete resources you created after confirming their identity. All outputs are expected, not observed; these are manual labs, not ByteMind runnable editors. Before contacting the Engine, verify the effective local endpoint including DOCKER_HOST, DOCKER_CONTEXT and CLI overrides. Recheck the approved local image ID and native platform; if the recorded digest is unavailable, report it as unknown rather than inventing one. Use owner-set resource and time limits. If prerequisites cannot be confirmed, do the paper exercise instead. Check that the approved fixture has no declared image volumes and that the synthetic destinations and file names are unused. The bind-mount lesson alone uses a fresh host directory; do not extend it to other paths.
Think of two copies
Imagine two containers created from the same image. Both begin with the same packaged files, but each has its own writable layer. A new file in one does not automatically appear in the other. The original image is not changed by ordinary writes inside a container. This is useful for disposable work, but a poor place for important records.
Stop is not deletion
Create a named container that writes a note and exits. Starting that same container again reruns its original command; the conditional test avoids overwriting the existing note. The first run should print created and first; starting it again should print preserved and first. Inspect the exit state before removing it. Check zero exit status and the expected first-run text before starting again. The fixture must not have a mount covering /tmp/note.
docker run --pull=never --network none --name bm-v06-layer busybox:1.37 sh -c 'if [ ! -f /tmp/note ]; then printf "first\n" > /tmp/note; printf "created\n"; else printf "preserved\n"; fi; cat /tmp/note'docker start -a bm-v06-layerdocker inspect --format '{{.State.Status}}' bm-v06-layerReplace the container
Only after confirming the note is synthetic, remove the stopped container. A different container from the original image should report missing. This distinguishes removing a container from merely stopping it. Data attached through mounts follows different rules, introduced next.
docker rm bm-v06-layerdocker run --rm --pull=never --network none busybox:1.37 sh -c 'if [ -f /tmp/note ]; then cat /tmp/note; else printf "missing\n"; fi'Manual practice
Predict the outputs of the initial run, start, inspect and replacement run. Explain why saving a note inside the writable layer is not a backup.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Docker writable layers: what happens to files? — Knowledge check
Apply the concepts from this lesson.
Which object receives an ordinary new file in an unmounted directory?
What happens to that file when the same container stops?
What should you expect after deleting that container and running its original image again?