CONTAINERS / A CONCEPT NOTE

Volumes & Persistence

data that survives restarts

~65 sec read

Overview · mechanism
pitfall · examples

01 / THE SHORT VERSION

The idea in a few sentences.

Container filesystems are ephemeral. Writable layers are destroyed when a container stops. Volumes mount a directory on the host's physical disk directly into the container filesystem.

02 / FOLLOW THE MECHANISM

How data persistence flows

  1. Volume Define

    user specifies mounting directory path (e.g. /var/lib/mysql) to host path.

  2. Mount syscall

    container runtime intercepts filesystem startup and mounts host directory.

  3. Writes

    application writes database transactions inside mount folder.

  4. Recreation

    container is deleted and recreated; new container mounts same directory, retaining all data.

04 / COMMAND NOTES

Read the command, then the result.

Inspect the flags and arguments before trying an example. Snippets can need local setup, replacement values, or resources in your own environment.

EXAMPLE 01 · REFERENCE

list local persistent volumes

docker volume ls

EXAMPLE 02 · REFERENCE

mount volume db_data inside database container

docker run -v db_data:/var/lib/mysql mysql

Explore command anatomy in the CLI lab