Data and networking
Separate data from containers
Understand the writable container layer and move durable application state into storage with an independent lifecycle.
8 minute lesson
A container can write files, but those files live in that container’s writable layer. Removing the container removes that layer.
Treat containers as replaceable. Put durable database or upload data in a volume, and put configuration in environment variables or mounted configuration files. This lets you update the image without treating one old container as precious.
docker volume create notes-data
docker volume inspect notes-data
A named volume has its own lifecycle, but persistence is not a backup. Accidental deletion, application bugs, and database corruption can all survive a container replacement. Define how the volume is backed up, where the backup is stored, and how a restore is tested before calling the data durable.
Use the writable container layer only for disposable runtime changes. Use a volume for state that must survive replacement, and a temporary filesystem for scratch data that should disappear. Do not edit Docker’s internal volume directory on the host; access the data through a container or a supported backup tool so ownership and filesystem assumptions remain consistent.
Create and inspect a named volume. Identify its Docker-managed name without editing its host storage directly.
Lesson completed