Making a container's data persist
The ephemeral writable layer and the three mounts (named volume, bind mount, tmpfs); the -v and --mount options; the docker volume commands; what survives stop, rm and a new image.
- 24 cards
- 5 topics
- Free
The outline, topic by topic
Each topic is weighted the way the exam weighs it.
- Concepts
- Questions
- Sort and link
- Scenarios
- Understand
A few cards from the deck
Writable layer: what is it?
Show the answer
A space belonging to one container where all the files it writes outside a mount go; it is destroyed along with it.
It survives
docker stopthendocker start, but notdocker rm. Writing into it is also slower than writing to a volume.You write
a.txtin/data(named volume),b.txtin/tmpandc.txtin/src(bind mount). You rundocker rmthendocker runwith the same mounts. Which files are still there?a.txtetc.txta.txtseulementa.txt,b.txtetc.txtb.txtetc.txt
Show the answer
a.txtetc.txt/tmpis in the writable layer, deleted with the container. The named volume lives outside the container, and the bind mount is a host folder: neither is touched bydocker rm.In
-v pgdata:/var/lib/postgresql/data,pgdatais the name of the … and/var/lib/postgresql/datathe path where it appears ….Show the answer
In
-v pgdata:/var/lib/postgresql/data,pgdatais the name of the volume and/var/lib/postgresql/datathe path where it appears inside the container.When the left part is a name, it is a named volume; when it starts with
/or./, it is a bind mount to the host.Named volume: what is it?
Show the answer
A storage space created and managed by Docker, designated by a name, which lives independently of any container.
Docker keeps it in its own folder (
/var/lib/docker/volumes/...): no host path needs to be chosen. It is the standard choice for a database's data.A
postgres:16container is started with no-voption. After each update of the image, the database is empty. What is the probable cause, and the fix?- The new image overwrites the tables at start-up; pin the image tag to
latest - The Docker daemon deletes databases after an update; turn off automatic updates
- The data stays attached to the old container; mount a named volume on the data folder
- The database port is not published; add the
-p 5432:5432option
Show the answer
The data stays attached to the old container; mount a named volume on the data folder
Updating the image forces the container to be re-created. Without
-v, thepostgres:16image keeps its data in an anonymous volume tied to the old container, which the new one does not pick up: it starts from an empty database. A named volume on/var/lib/postgresql/datais attached to each new container.- The new image overwrites the tables at start-up; pin the image tag to