You need Docker running (set up in lesson 3.1.1), and a terminal. Everything happens on your machine; nothing is pushed.
About the commands
Every container here runs alpine:3.22, a tiny Linux image, with one shell command: add a line with the time to a notes file, then print the file. Each new line is one "run". Your times will differ from the ones shown, and they are in UTC: containers use UTC unless told otherwise, so the hour may not match your clock.
On Windows, use PowerShell with Docker Desktop. Write ${PWD} where the steps say $PWD.
Write a note in a container
docker run --name notes-demo alpine:3.22 sh -c 'echo "note written at $(date +%T)" >> /notes.txt; cat /notes.txt'The container runs the command and exits. It still exists, stopped, with its writable layer.
You should seeOne line, such as note written at 01:50:34.
Start the same container again
docker start -a notes-demostartreruns the same container, and-ashows its output. The first note is still there: same container, same layer.You should seeTwo lines: the first note, and a new one.
Replace the container
docker rm notes-demo docker run --name notes-demo alpine:3.22 sh -c 'echo "note written at $(date +%T)" >> /notes.txt; cat /notes.txt' docker rm notes-demoThis is what an update does: remove the old container, start a new one from the image. The new one began with an empty layer.
Check yourself
You should seeOne line again. The earlier notes are gone.
Create a volume
docker volume create notes-dataYou should seenotes-data, printed back.
Write to the volume from two containers
docker run --rm -v notes-data:/data alpine:3.22 sh -c 'echo "note written at $(date +%T)" >> /data/notes.txt; cat /data/notes.txt' docker run --rm -v notes-data:/data alpine:3.22 sh -c 'echo "note written at $(date +%T)" >> /data/notes.txt; cat /data/notes.txt'--rmdeletes each container as it exits, so these are two different containers. The notes survive because they're on the volume at/data, not in either container.You should seeOne line after the first command, two after the second.
Try a bind mount
mkdir notes-folder docker run --rm -v "$PWD/notes-folder:/data" alpine:3.22 sh -c 'echo "written by the container" >> /data/notes.txt' cat notes-folder/notes.txtOpen
notes-folder/notes.txtin your editor too: it's an ordinary file.You should seewritten by the container, read from a file on your machine.
Clean up
docker volume rm notes-data docker volume ls --filter name=notes rm -r notes-folderDeleting a volume deletes its data, and it can't be undone.
You should seenotes-data printed by rm, and no notes-data in the list.
What you proved
The container's own filesystem lasted exactly as long as the container. The volume and the folder lasted as long as you wanted them to, because they were never inside a container.
If docker volume rm says the volume is in use
It prints volume is in use and a container ID when a container, even a stopped one, still has it mounted. Run docker ps -a to find it, remove it with docker rm -f <name>, then delete the volume again.