Skip to the workspace
Pebellslearn by building
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.

docker / The Ephemeral Container Filesystem

Explore each scene at your own pace.

01 · The rule

The rule

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.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.