SteelReed

Search

Search posts, questions…

DevOps & CloudQuestion 14 / 35

Junior

What is a Docker volume? How do named volumes, bind mounts and tmpfs differ?

Short answer

Files written in a container live in the temporary writable layer and are lost when the container is removed; data you must keep goes in a volume, outside the container's lifecycle. Three kinds: named volume, bind mount, tmpfs.

DB, uploads to keepcode, config in devsecrets, temp filesno need to keepWhat is the data?Named volumeBind mount host foldertmpfs in RAMWritable layer, gone on rm

3 points to say:

  1. Named volume (managed by Docker) for DB data, bind mount for code/config in dev, tmpfs for sensitive temp files.
  2. An empty named volume gets the image's content copied in; a bind mount hides whatever was at that path.
  3. docker compose down keeps volumes, only down -v deletes them; use --mount so a wrong mount fails loudly.

Keep reading the deep dive

Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.