volumes (compose): Declares named volumes and mounts them into services for persistent data that outlives container restarts. In Docker Compose, the top-level volumes section declares named volumes, and services mount them, as in db-data:/var/lib/postgresql/data. Named volumes keep data when containers are stopped, removed or recreated. That is essential for databases in development. Without a volume, docker compose down and up would give you an empty database every time.
Frequently asked questions about volumes (compose)
What should you keep in mind with volumes (compose)?
Named volumes are managed by Docker and listed with docker volume ls. docker compose down -v removes them together with the containers, which is handy for a clean start and dangerous when you did not mean it. For code, use bind mounts to your project folder instead, so edits appear immediately. Back up important volumes, for example with a database dump, because they live only on that one machine.
What does an example of volumes (compose) look like?
Use this skill when creating, modifying, or debugging Docker Compose configurations, even if the user just says they need to wire services together, add a database to their stack, or set up a local development environment with multiple containers. Covers service definitions, health checks, dependency ordering, volumes, networks, environment variables, and development overrides.
Use this skill before running, or recommending, any Docker command that deletes, wipes, resets, or otherwise irreversibly changes state — even if the user just says to "clean up", "clear the cache", "start fresh", "wipe everything", "nuke it", "reset", "force remove", or "tear down" Docker resources. Covers generic Docker CLI destructive operations not owned by a more specific skill — `docker rm`,
Use this skill when setting up, initializing, or Dockerizing a project, even if the user doesn't explicitly mention Docker but describes a need for containerized local development, adding a database or cache dependency, or running services without host-level installs. Covers Dockerfile, compose.yaml, and .dockerignore creation with Docker best practices.