DOCKER · Learning guideTheory · Labs · Knowledge checks
Chapter 05

Persistent storage and volumes

Ephemeral filesystems

A container writable layer is removed with the container. Store durable application data in volumes or explicitly managed bind mounts.

docker volume create training-data
docker run --rm -v training-data:/data alpine sh -c "echo persistent > /data/note.txt"
docker run --rm -v training-data:/data alpine cat /data/note.txt
Hands-on lab: Verify the file survives the removal of its first container.

Volumes versus bind mounts

Named volumes are Docker-managed. Bind mounts map an explicit host path and are useful for development, but introduce host-path and permission dependencies.

docker volume ls
docker volume inspect training-data
Hands-on lab: Describe a use case for each storage type.

Backups and cleanup

Back up application data consistently, especially databases, and test restores. Removing containers does not automatically remove named volumes.

docker volume rm training-data
Hands-on lab: Remove the training volume after validating the exercise.