Skip to main content

CV-M004: Undefined volume reference

Error Semantic

Why This Matters

A service references a named volume that is not defined in the top-level volumes section. Docker Compose will fail at startup when a service mounts a named volume that does not exist in the top-level declaration. Bind mounts (paths starting with ./, /, or ~) and anonymous volumes (single container path) do not require top-level declarations. Only named volumes (source:target where source is a plain name) must be declared.

How to Fix

Define the referenced volume in the top-level volumes section.

Before (incorrect)

services:
  db:
    volumes:
      - pgdata:/var/lib/postgresql/data
# No top-level volumes defined

After (correct)

services:
  db:
    volumes:
      - pgdata:/var/lib/postgresql/data
volumes:
  pgdata:

Rule Details

Rule Code
CV-M004
Severity
Error
Category
Semantic

Related Rules