0
0
Dockerdevops~30 mins

Container filesystem is ephemeral in Docker - Mini Project: Build & Apply

Choose your learning style9 modes available
Understanding Container Filesystem Ephemeral Nature
📖 Scenario: You are learning how Docker containers handle files inside their filesystem. Containers have a temporary filesystem that resets when the container stops. This means any files created inside the container at runtime will be lost after it stops unless you use special methods like volumes.
🎯 Goal: Build a simple Docker container, create a file inside its filesystem at runtime, then observe that the file disappears after the container stops, demonstrating the ephemeral nature of container filesystems.
📋 What You'll Learn
Create a Dockerfile that uses the alpine image
Add a CMD to keep the container running
Build and run the container detached, create tempfile.txt at runtime using docker exec, and check that the file exists
Stop and remove the container, then verify that the file is gone when starting a new container from the same image
💡 Why This Matters
🌍 Real World
Containers are widely used to run applications in isolated environments. Understanding ephemeral filesystems prevents data loss in deployments.
💼 Career
DevOps engineers must manage persistent storage with volumes for stateful apps like databases.
Progress0 / 4 steps
1
Create a Dockerfile with Alpine base image
Create a file named Dockerfile with a single line that sets the base image to alpine.
Docker
Need a hint?

The first line in a Dockerfile usually starts with FROM followed by the image name.

2
Add CMD to keep the container running
Add a CMD instruction in the Dockerfile to run sleep 3600. This keeps the container alive so we can execute commands inside it later.
Docker
Need a hint?

Use CMD sleep 3600 (shell form) to make the container run indefinitely for this demo.

3
Build, run detached container, create and check the file
Build the Docker image with tag ephemeral-test. Run a detached container named ephemeral-container. Use docker exec to create /tempfile.txt with content Hello from container, then cat it to verify.
Docker
Need a hint?

Build with docker build -t ephemeral-test ., run detached with -d --name, create file with docker exec ... sh -c 'echo ...'.

4
Stop container and demonstrate ephemeral filesystem
Confirm file exists with ls, then stop and remove the container. Run a new container from the same image and check ls /tempfile.txt fails, proving the file was ephemeral.
Docker
Need a hint?

Run docker exec ... ls /tempfile.txt (outputs /tempfile.txt), stop/rm, then new docker run --rm ... ls /tempfile.txt (outputs error).