Bitpath

Lesson 1 · Unit 03

Volumes and bind mounts

Named volumes for data that must last, bind mounts for your source

13 exercisesabout 3 min

What you practise

  • Named volumes against bind mounts, data that outlives the container, mounting source code in development

Try a question from this lesson

Pick one

A database container keeps its tables in its own /var/lib/data. To upgrade, you remove it and start a container from a newer image. Where are the tables now?

Hint

Where does a container keep the files it writes, and what does docker rm do to that place?

The ideas

Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.

Concept

A named volume

A volume is storage that Docker manages on the host, outside every container. -v NAME:PATH mounts it at a path inside.

Whatever the container writes under that path lands in the volume. Removing the container leaves the volume alone, and the next container that mounts it finds the same files.

shell
docker run -d --name db \
  -v pgdata:/var/lib/postgresql/data \
  -e POSTGRES_PASSWORD postgres:17

Concept

A bind mount

A bind mount puts a host directory that you choose into the container. Write a path where a volume name would go.

Both sides see the same files. Edit on the host and the container has the change at once; write in the container and the file appears on the host. Ideal for source code while you develop.

shell
docker run -d -p 8000:8000 \
  -v "$(pwd)":/app shop/api:dev

10 more exercises in the app

  • 2× type the answer
  • 2× true or false
  • 4× multiple choice
  • 1× match the pairs
  • 1× fill the blanks

Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.

One email when Bitpath is ready to try. Nothing else. Privacy