9.4.1.3 Up Volume Creation
A focused guide to Up Volume Creation, connecting core concepts with practical Docker and container operations.
Up volume creation is the part of docker compose up's overall behavior responsible for automatically creating any named volumes a Compose file declares, ensuring they exist and are ready to be mounted by whichever services reference them, before those services actually start.
Automatic Creation of Declared Volumes
A declared volume not already present is created automatically the first time up needs to start a service that references it.
services:
db:
image: postgres:16
volumes:
- pgdata:/var/lib/postgresql/data
volumes:
pgdata:
docker compose up -d
docker volume ls
myapp_pgdata
This volume was created automatically as part of this up invocation, ready to be mounted into the db service's container.
Why an Already-Existing Volume Isn't Recreated
A subsequent up invocation reuses an already-existing volume rather than recreating it, preserving whatever data that volume already holds.
docker compose up -d
docker compose down
docker compose up -d
Data within pgdata survives this entire sequence, since down (without -v) doesn't remove volumes, and the subsequent up correctly reattaches to the existing, already-created volume rather than creating a fresh one.
How External Volumes Differ From This Automatic Creation
A volume declared with external: true is never created by up — Compose expects it to already exist, simply attaching to it rather than attempting to create it.
volumes:
shared-data:
external: true
Verifying Volume Creation Succeeded
Confirming a declared volume was actually created, and inspecting its configuration, validates this part of the startup process completed as expected.
docker volume inspect myapp_pgdata
Why Up Volume Creation Matters
This automatic volume provisioning ensures a Compose application's declared persistent storage needs are reliably met without requiring a separate, manual volume creation step, while still correctly preserving existing data across repeated up invocations.