Menu

Docker Compose volumes: four mix-ups that can cost you data
📰

Docker Compose volumes: four mix-ups that can cost you data

DEV Community: beginners·Frank Zhang·6 days ago
#gSHYm9Aa
#devtobeginners#devto#dev#volume#compose
Reading 0:00
15s threshold

Most people learn early on that docker compose down followed by up keeps the database. Fewer can say why, and that gap is where data gets lost: someone copies down -v from a tutorial, or assumes :ro protects a volume from everything.

Here's a short quiz. Which of these are true?

A. A volume declared under top-level volumes: but not mounted by any service makes docker compose up fail.

B. Adding :ro to a service's volume mount makes it read-only inside that container.

C. With external: true , Compose looks for an existing volume instead of creating one.

D. A named volume that a service references and that is declared at the top level gets created automatically, using the default driver.

B, C and D are true. A is false. The rest of this post goes through why.

Declaring is not mounting

services : app : image : alpine:3.21 command : sleep 3600

volumes : app_data :

Enter fullscreen mode

Exit fullscreen mode

This is valid. app_data is defined, but nothing uses it, and up doesn't complain.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.