Linux Labs

Containers: Docker and compose / Stage 5 of 11

Volumes: data outlives the container

Not running Starting usually ~20 s
Leave the lesson

Step 1 of 7 · on a machine · 5 min

The notes are gone

What you will learn

  • Explain where a container keeps the files it writes and when they disappear.
  • Attach a named volume and a host directory with -v and find them on the container.
  • Give host directory files permissions that let the process in the container read them.

The notes service runs in a container: busybox serves files from the /data directory over HTTP, and the notes are in /data/notes.txt. To change a setting, the container is re-created — removed and started again from the same notes:1 image, as in the previous module.

Look at the notes, re-create the container and look into /data again. “Start” will launch docker and the service.

Exercise · look

Re-create the container with the notes

Print the notes from the notes container, remove the container, create it again from the notes:1 image and look at what is in /data.

First, predict

The new container is created from the same notes:1 image. What will ls -A /data show in it?

Now start the exercise, run the command and compare your prediction with the output.

Sign in and start The machine is available after signing in
Check yourself 1 question

Where were the notes before docker rm?

  • cat read the notes from the /data/notes.txt file on the container's disk. The file itself is gone: ls -A /data is empty.

  • The old container is gone: docker ps -a showed one notes, the new one, with the Up status.

  • The new container from the same notes:1 started with an empty /data: the image holds no notes.

The notes were in the container's own files, and docker rm removed them together with it.

Ubuntu 24.04
Loading…