Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Data Persistence  ›  Lesson

The Ephemeral Container Filesystem

Ephemeral Container Filesystem 12 minFiles a container writes live in its writable layer, which survives stop and start but is deleted with the container, and a new container from the same image always starts fresh.

The Ephemeral Container Filesystem

A tester adds twenty notes to quicknotes, which saves them in /app/notes.db inside its container. You ship a new version: build, remove the old container, run the new one. The twenty notes are gone. Nothing crashed; this is exactly how containers are designed to behave.

The rule

The writable layer dies with the container, not with a stop.

Recall the layers: the image is read-only, and each container gets its own thin writable layer on top. Every file a container creates or changes lands there. That layer's life is tied to the container, not to the process inside it:

Action Writable layer
docker stop then docker start kept
docker restart, or a crash with a restart policy kept
docker rm deleted
New container from the same image starts empty

So data in the writable layer is ephemeral: safe across stops, lost on replacement. And in Docker, replacement is the normal way to change anything. Upgrading, changing a setting or recovering from a broken state all mean "remove and run a new container".

docker run -d --name notes -p 8080:5000 quicknotes:1.0
# ... notes are added ...
docker rm -f notes
docker run -d --name notes -p 8080:5000 quicknotes:1.0
# a fresh writable layer: the notes are gone

You can see what a container has changed compared with its image:

docker diff notes

It lists files Added, Changed or Deleted in the writable layer. Seeing your data file there is a warning sign.

The writable layer is also the wrong place for heavy writing: going through the union filesystem is slower than writing to a volume, and its size is hard to manage.

The shortcut

For every file an app writes, ask "Would I cry if the container were replaced?" If yes, it must live outside the writable layer. Temporary files and caches can stay; data cannot.

Sorting quicknotes' filesStep 1 of 4
  1. /app/notes.db

    The users' notes. Losing them on replacement is unacceptable. Must move outside the container.

Drills

Answer fast — trust the rule.

quick drill

A container is stopped with docker stop and started again. What happened to files it wrote?

quick drill

You remove the quicknotes container and run a new one from the same image. What does the new one see at /app/notes.db?

quick drill

Which command lists files a container has added, changed or deleted compared with its image?

quick drill

Which file is safe to leave in the container's writable layer?

Remember

  • The writable layer dies with the container, not with a stop.
  • Shortcut: "would I cry if the container were replaced?" Yes → store it outside.
  • Trap: in Docker, replacing the container is the normal upgrade, so ephemeral data is lost routinely.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainWhere did my notes go?

A user saved notes in quicknotes, which writes them to /app/notes.db inside the container. After you rebuilt the image and ran a new container, the notes were gone. Explain exactly why, and what would and would not have kept them.