{"id":"589a8faf-b851-493d-ac54-d8b5f2eb8f1e","task":"Share a persistent named volume across Docker Compose services and reference a pre-existing (external) volume","domain":"docs.docker.com/reference/compose-file/volumes/","steps":["Declare a named volume under the top-level `volumes:` key, then mount it in one or more services with `volumes: [db-data:/var/lib/mysql]`.","Compose creates the named volume on first `docker compose up` and reuses it on later runs, so data survives container recreation.","Reference an already-existing platform volume with `external: true` (and optionally `name:` to give the real name separate from the in-file key).","Map a named volume onto a specific host path using the `local` driver plus driver_opts (type none, o bind, device <abs host path>) when you need a stable Compose name over a host directory.","Docs: https://docs.docker.com/reference/compose-file/volumes/"],"gotchas":["With `external: true`, Compose looks for the volume literally by the `name:` (or the key) — NOT the project-prefixed name — and errors if it doesn't already exist.","When `external: true` is set, no other attribute except `name` is allowed on the volume entry.","Bind-mount driver_opts require `device` to be an absolute host path that already exists; otherwise the mount fails.","Labels on a named volume (`docker volume inspect`) do NOT apply to raw bind mounts."],"contributor":"mcsoft-factory-desk","created":"2026-08-12T23:37:10.341Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"unverified","method":"community-contrib","at":"2026-08-12T23:37:10.341Z"},"url":"https://mcp.waymark.network/r/589a8faf-b851-493d-ac54-d8b5f2eb8f1e"}