Ephemeral Container Filesystems & Why Data Gets Lost
Learn why writable container layers vanish on remove and when to use persistent mounts.
In plain words
Files written by the app last only as long as the container’s writable filesystem exists unless they live on mounted storage.
Think of it like…
The container filesystem is a hotel room: restarting your stay preserves the notepad, but checkout removes or resets the room; luggage stored in a locker has a separate lifecycle.
Where you’ve seen it
In practice, docker run --name demo -v demo-data:/var/lib/demo alpine:3.21 sh -c "echo durable > /var/lib/demo/state"; docker rm -f demo is the concrete move for this job: learn why writable container layers vanish on remove and when to use persistent mounts. The release is not accepted until start a replacement with the same demo-data volume and cat /var/lib/demo/state confirms the result.
Words you’ll hear
- Ephemeral FS
- The implementation control in
docker run --name demo -v demo-data:/var/lib/demo alpine:3.21 sh -c "echo durable > /var/lib/demo/state"; docker rm -f demofor learn why writable container layers vanish on remove and when to use persistent mounts. - Writable Layer
- The result to observe with
start a replacement with the same demo-data volume and cat /var/lib/demo/state, rather than infer from a successful command alone. - Persistence
- The production boundary exposed when believing docker restart erases data, or deleting the container and later looking for files written under /tmp without a mount.
Visual diagram
Theory & deep dive
Ephemeral FS control path
The concrete mechanism is docker run --name demo -v demo-data:/var/lib/demo alpine:3.21 sh -c "echo durable > /var/lib/demo/state"; docker rm -f demo. The observable result is start a replacement with the same demo-data volume and cat /var/lib/demo/state; if those disagree, inspect the runtime evidence before changing unrelated settings.
Learn why writable container layers vanish on remove and when to use persistent mounts. Keep Ephemeral FS, Writable Layer and Persistence in the same deployment record so the intent and the observed state cannot drift apart.
docker run --name demo -v demo-data:/var/lib/demo alpine:3.21 sh -c "echo durable > /var/lib/demo/state"; docker rm -f demo
start a replacement with the same demo-data volume and cat /var/lib/demo/state, not with command success alone.Persistence failure boundary
Replacing an app with a new container should be safe and routine, but the same action is destructive for SQLite, uploads and database data kept in the image overlay. Immutable deployment only works when mutable state has an explicit owner outside the disposable container. The narrow failure to design for is believing docker restart erases data, or deleting the container and later looking for files written under /tmp without a mount.
Accept this compromise explicitly: Ephemeral layers make rollbacks clean; persistence introduces lifecycle, backup and latency responsibilities that an image must not hide. The controlled check-start a replacement with the same demo-data volume and cat /var/lib/demo/state-also identifies the point where a different design is safer.
Exercise this failure safely: believing docker restart erases data, or deleting the container and later looking for files written under /tmp without a mount.
How it works, step by step
Step 1 of 41. State the boundary
Write down why the workload needs this: Replacing an app with a new container should be safe and routine, but the same action is destructive for SQLite, uploads and database data kept in the image overlay. Immutable deployment only works when mutable state has an explicit owner outside the disposable container.
- Intent
- Ephemeral FS
When to use it & trade-offs
What it is
A container’s image layers are read-only; ordinary writes go to a per-container writable layer. docker rm deletes that layer, while a mounted named volume or external database survives replacement. restart and rm therefore have very different persistence guarantees.
Why it matters: Replacing an app with a new container should be safe and routine, but the same action is destructive for SQLite, uploads and database data kept in the image overlay. Immutable deployment only works when mutable state has an explicit owner outside the disposable container.
When to reach for it
- The fit is strongest for this job: learn why writable container layers vanish on remove and when to use persistent mounts. Pair it with
start a replacement with the same demo-data volume and cat /var/lib/demo/statein the runbook. - Production Ephemeral FS changes should make Writable Layer observable through
docker run --name demo -v demo-data:/var/lib/demo alpine:3.21 sh -c "echo durable > /var/lib/demo/state"; docker rm -f demo, rather than trusting the runtime default. - Keep a rollback example for the case where believing docker restart erases data, or deleting the container and later looking for files written under /tmp without a mount.
When to avoid or be careful
- Do not accept command success while the system can still fail by believing docker restart erases data, or deleting the container and later looking for files written under /tmp without a mount.
- Avoid erasing Persistence protection merely to dodge this cost: “Ephemeral layers make rollbacks clean; persistence introduces lifecycle, backup and latency responsibilities that an image must not hide”.
- Do not replace the evidence path-
start a replacement with the same demo-data volume and cat /var/lib/demo/state-with a screenshot or a mutable tag.
docker run --name demo -v demo-data:/var/lib/demo alpine:3.21 sh -c "echo durable > /var/lib/demo/state"; docker rm -f demo: practical choices
Strengths: A container’s image layers are read-only; ordinary writes go to a per-container writable layer. docker rm deletes that layer, while a mounted named volume or external database survives replacement. restart and rm therefore have very different persistence guarantees.
Watch out: Ephemeral layers make rollbacks clean; persistence introduces lifecycle, backup and latency responsibilities that an image must not hide.
Strengths: It can begin with docker run --name demo -v demo-data:/var/lib/demo alpine:3.21 sh -c "echo durable > /var/lib/demo/state"; docker rm -f demo and fewer surrounding controls.
Watch out: It silently accepts believing docker restart erases data, or deleting the container and later looking for files written under /tmp without a mount, which makes the result hard to reproduce after promotion.
Strengths: Replacing an app with a new container should be safe and routine, but the same action is destructive for SQLite, uploads and database data kept in the image overlay. Immutable deployment only works when mutable state has an explicit owner outside the disposable container.
Watch out: The platform adds an ownership and debugging layer; retain start a replacement with the same demo-data volume and cat /var/lib/demo/state as the direct check.
Interview signals & numbers to know
When this topic comes up
- docker run --name demo -v demo-data:/var/lib/demo alpine:3.21 sh -c "echo durable > /var/lib/demo/state"; docker rm -f demo
- start a replacement with the same demo-data volume and cat /var/lib/demo/state
- Failure signature: believing docker restart erases data, or deleting the container and later looking for files written under /tmp without a mount
- Trade-off: Ephemeral layers make rollbacks clean; persistence introduces lifecycle, backup and latency responsibilities that an image must not hide.
Benchmarks & rules of thumb
- 2 lifecycles
- container writable layer and mounted volume
- 1 rm operation
- destroys the unmounted writable layer
- 0 durability guarantees
- for ordinary overlay writes after container deletion
Common mistakes & follow-ups
Common interview mistakes
- Treating a successful
docker run --name demo -v demo-data:/var/lib/demo alpine:3.21 sh -c "echo durable > /var/lib/demo/state"; docker rm -f demoas proof and skippingstart a replacement with the same demo-data volume and cat /var/lib/demo/state. - Believing docker restart erases data, or deleting the container and later looking for files written under /tmp without a mount
- Optimizing Ephemeral FS without accepting that ephemeral layers make rollbacks clean; persistence introduces lifecycle, backup and latency responsibilities that an image must not hide.
Likely interviewer follow-ups
- Why does
docker run --name demo -v demo-data:/var/lib/demo alpine:3.21 sh -c "echo durable > /var/lib/demo/state"; docker rm -f demoaddress Ephemeral FS here rather than through application code? - How would you distinguish healthy Writable Layer from the failure “believing docker restart erases data, or deleting the container and later looking for files written under /tmp without a mount” using
start a replacement with the same demo-data volume and cat /var/lib/demo/state? - When would this trade-off-“Ephemeral layers make rollbacks clean; persistence introduces lifecycle, backup and latency responsibilities that an image must not hide”-justify a different Persistence design?
docker run --name demo -v demo-data:/var/lib/demo alpine:3.21 sh -c "echo durable > /var/lib/demo/state"; docker rm -f demo-and one proof-start a replacement with the same demo-data volume and cat /var/lib/demo/state. Then name the boundary: believing docker restart erases data, or deleting the container and later looking for files written under /tmp without a mount.Knowledge check
Put it into practice
Practice related interview Q&A
Apply Ephemeral Container Filesystems & Why Data Gets Lost with generative AI interview Q&A and hands-on practice.