# Demonstration: Proving Data Loss, Then Proving Persistence ## OBSERVE ``` $ docker run -d --name no-volume alpine:3.19 sleep 300 $ docker exec no-volume sh -c "echo important-data > /tmp/data.txt" $ docker exec no-volume cat /tmp/data.txt important-data ``` Data exists — but is it actually safe? ## HYPOTHESIS Predict: will `/tmp/data.txt` still exist if this exact container is destroyed and an identical new one is started? ## INSPECT ``` $ docker rm -f no-volume $ docker run -d --name no-volume alpine:3.19 sleep 300 $ docker exec no-volume cat /tmp/data.txt cat: /tmp/data.txt: No such file or directory ``` Gone — proven, not assumed. The "new" container is a completely fresh writable layer, even though it has the exact same name and image. ## CHANGE Now with a named volume instead: ``` $ docker rm -f no-volume $ docker volume create demo-vol $ docker run -d --name with-volume -v demo-vol:/data alpine:3.19 sleep 300 $ docker exec with-volume sh -c "echo important-data > /data/data.txt" $ docker rm -f with-volume $ docker run -d --name with-volume -v demo-vol:/data alpine:3.19 sleep 300 ``` ## VERIFY ``` $ docker exec with-volume cat /data/data.txt important-data ``` Proven, not assumed — the exact same destroy-and-recreate sequence, but this time the data survived, because it lived in the volume, not the container's disposable writable layer. ## Instructor Notes **Demo goal:** Prove BOTH the loss and the persistence with real destroy/recreate cycles — the contrast is what makes this lesson land, not either half alone. **Approximate timing:** 10 minutes live. **Common mistake to watch for:** stopping (not removing) a container and concluding "data persists" — `docker stop` doesn't touch the writable layer at all; only `docker rm` (destroying the container entirely) actually tests real persistence.