Interview's MateDocker
Interview's Mate

Docker

Compose · Networking · Security · Ops

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Docker topics
Lesson 41/ 160
03. Storage, Volumes & Data Persistence

Ephemeral Container Filesystems & Why Data Gets Lost

Learn why writable container layers vanish on remove and when to use persistent mounts.

BeginnerEphemeral FS · Writable Layer3 quiz questions
Practice DevOps Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

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 demo for 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

Loading interactive 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.

Concrete Ephemeral FS setup

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

Key takeaway: Prove Writable Layer with 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.

Deliberate failure test

Exercise this failure safely: believing docker restart erases data, or deleting the container and later looking for files written under /tmp without a mount.

Key takeaway: Ephemeral layers make rollbacks clean; persistence introduces lifecycle, backup and latency responsibilities that an image must not hide.

How it works, step by step

Step 1 of 4
Design

1. 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.

Files written by the app last only as long as the container’s writable filesystem exists unless they live on mounted storage.
Key numbers at this step
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/state in 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

Explicit Ephemeral FS
Best for: Learn why writable container layers vanish on remove and when to use persistent mounts, with a reviewed runbook.

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.

Ambient default
Best for: Short-lived Writable Layer experiments with low blast radius.

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.

Managed Persistence
Best for: Teams that centralize Persistence policy across many workloads.

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 demo as proof and skipping start 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 demo address 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?
Interview tip: Give one concrete operation-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

Loading quiz

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.

Open DevOps Q&A →Tech Learn Q&A
Previous topic
Dockerfile Linting & Best Practices with Hadolint
Next topic
Docker Storage Drivers (overlay2, btrfs, zfs)