Docker named volumes: store data beyond a container
Lab prerequisites
Use only an approved disposable, offline Linux VM with a local Docker Engine, ordinary local volume driver, and reviewed preloaded busybox:1.37 (record its digest, platform, exact Engine version and required utilities first). Verify the active Docker context and endpoint; every bm-v06 resource name in the lesson must be unused before starting. Never reuse a pre-existing volume. Use a dedicated lab shell, run commands individually in order, and stop on unexpected errors (the explicitly labeled negative tests are exceptions). Only delete resources you created after confirming their identity. All outputs are expected, not observed; these are manual labs, not ByteMind runnable editors. Before contacting the Engine, verify the effective local endpoint including DOCKER_HOST, DOCKER_CONTEXT and CLI overrides. Recheck the approved local image ID and native platform; if the recorded digest is unavailable, report it as unknown rather than inventing one. Use owner-set resource and time limits. If prerequisites cannot be confirmed, do the paper exercise instead. Check that the approved fixture has no declared image volumes and that the synthetic destinations and file names are unused. The bind-mount lesson alone uses a fresh host directory; do not extend it to other paths.
Give the data its own name
A volume is a separately managed storage object. Use one for application-generated records that should not disappear with the process or container. Docker manages its location; applications read and write through an attached path. The volume is not a backup and is not automatically available on a different daemon.
Create and attach
The name is bm-v06-notes and the directory inside the container is /data. Docker can create a missing named volume on run, but explicit creation makes the intended resource visible. The command writes a tiny synthetic note. The second container reads the note from the same volume, not from the first container. Expected output: blue.
docker volume create bm-v06-notesdocker run --rm --pull=never --network none --mount type=volume,src=bm-v06-notes,dst=/data busybox:1.37 sh -c 'printf "blue\n" > /data/note'docker run --rm --pull=never --network none -v bm-v06-notes:/data busybox:1.37 cat /data/noteNames, initial contents and inspection
A mount without a supplied volume name can create an anonymous volume. It has a generated identity and is not automatically chosen again by the next run. A new empty volume may receive existing files from its container destination by default; a nonempty volume can conceal those files. volume-nocopy opts out of initial copying with --mount. Inspect the name and driver, not the raw daemon storage directory. The last command deletes only this lab volume and its contents; run it after both containers exit. An empty volume can be populated when first mounted over existing destination content; it is not an ongoing synchronization mechanism. With volume-nocopy, the underlying destination remains hidden even though its files are not copied.
docker volume inspect --format '{{.Name}} {{.Driver}}' bm-v06-notesdocker volume rm bm-v06-notesManual practice
Draw the two containers pointing to the same named volume. Explain why a second container using another volume name would not read blue.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Docker named volumes: store data beyond a container — Knowledge check
Apply the concepts from this lesson.
Which part of src=bm-v06-notes,dst=/data is the volume name?
What does --rm do to a named volume after its container exits?
Which option prevents default copying of destination files into an empty volume?