0
0
Dockerdevops~10 mins

Container filesystem is ephemeral in Docker - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Container filesystem is ephemeral
Start Container
Container Filesystem Created
Write Files Inside Container
Stop & Remove Container
Container Filesystem Deleted
Start New Container
Fresh Filesystem, No Previous Data
This flow shows how a container's filesystem is created fresh at start, changes are temporary, and are lost when the container is stopped and removed.
Execution Sample
Docker
docker run -d --name test1 alpine sh -c "echo hello > /file.txt && sleep 3600"
docker stop test1
docker rm test1
docker run --name test2 alpine cat /file.txt
This sequence creates a container that writes a file, stops and removes it, then starts a new container trying to read that file.
Process Table
StepCommandActionFilesystem StateOutput
1docker run -d --name test1 alpine sh -c "echo hello > /file.txt && sleep 3600"Start container and write fileFile /file.txt created with content 'hello'
2docker stop test1Stop containerFilesystem still exists but container stopped
3docker rm test1Remove container and its filesystemFilesystem deleted
4docker run --name test2 alpine cat /file.txtStart new container and try to read fileFresh filesystem, no /file.txtcat: /file.txt: No such file or directory
💡 New container has a fresh filesystem; previous container's files are lost because container filesystem is ephemeral.
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4
Filesystem /file.txtabsentpresent with 'hello'present with 'hello'deletedabsent
Key Moments - 2 Insights
Why can't the new container read the file created by the old container?
Because each container has its own temporary filesystem that is deleted when the container is removed, as shown in step 3 where the filesystem is deleted.
Does stopping a container delete its filesystem?
No, stopping only pauses the container but the filesystem remains until the container is removed, as seen between steps 2 and 3.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the output when the new container tries to read /file.txt?
A"hello"
BEmpty output
C"cat: /file.txt: No such file or directory"
DError: container not found
💡 Hint
Check step 4 in the execution table under Output column.
At which step is the container filesystem deleted?
AStep 3
BStep 2
CStep 1
DStep 4
💡 Hint
Look at the Action and Filesystem State columns in the execution table.
If we did not remove the first container, what would happen when starting the second container?
AThe second container would see the file /file.txt
BThe second container would still have a fresh filesystem
CDocker would throw an error about container name conflict
DThe file would be empty
💡 Hint
Container names are test1 and test2 (different), so no name conflict. Each container has its own independent fresh filesystem.
Concept Snapshot
Container filesystem is temporary.
Files created inside a container exist only while it runs.
Stopping a container keeps filesystem; removing deletes it.
New containers start with a clean filesystem.
Use volumes to keep data persistent outside containers.
Full Transcript
When you start a Docker container, it creates a fresh filesystem. Any files you create inside exist only while the container runs. If you stop the container, the filesystem stays but the container is paused. When you remove the container, its filesystem is deleted. Starting a new container creates a new fresh filesystem without any files from the old container. This means container filesystems are ephemeral, or temporary. To keep data beyond container life, you use volumes. This example showed creating a file in one container, stopping and removing it, then starting a new container that could not see the old file.