dcg

Docker Compose

containers.compose

Protects against destructive Docker Compose operations like 'down -v' which removes volumes

  • 4blocking rules
  • 7safe patterns
  • 1Critical
  • 2High
  • 1Medium
~/.config/dcg/config.toml
[packs]
enabled = ["containers.compose"]

Evaluated when a command contains docker-compose, podman-compose, compose.

Recorded verdicts

  • docker compose down -vBlockedcontainers.compose:down-volumes

Blocking rules

Each rule ID is containers.compose:<name>. Use it in allowlists and [policy.rules].

  1. down-volumes

    Critical

    docker-compose down -v removes volumes and their data permanently.

    Explanation
    The -v/--volumes flag causes docker-compose down to remove named volumes declared in the volumes section of the Compose file, as well as anonymous volumes attached to containers. This permanently destroys: - Database data (PostgreSQL, MySQL, MongoDB volumes) - User uploads and application state - Any persistent configuration stored in volumes Safer alternatives: - docker-compose down: Stops and removes containers without touching volumes - docker-compose stop: Stops containers, preserving everything - docker volume ls: List volumes before removal
  2. down-rmi-all

    High

    docker-compose down --rmi all removes all images used by services.

    Explanation
    The --rmi all flag removes all images used by services in the Compose file. This forces re-downloading or rebuilding images on next 'up': - Base images must be pulled again (bandwidth, time) - Custom built images need rebuilding - Layers not in registry are lost Safer alternatives: - docker-compose down: Preserves images for faster restarts - docker-compose down --rmi local: Only removes images without custom tag - docker image ls: Review images before removal
  3. rm-volumes

    High

    docker-compose rm -v removes volumes attached to containers.

    Explanation
    The -v flag with docker-compose rm removes anonymous volumes attached to the containers being removed. This can cause data loss if volumes contain: - Application state or session data - Cached data that takes time to rebuild - Temporary but important processing results Safer alternatives: - docker-compose rm: Removes containers without volumes - docker-compose stop: Stops without removing anything - docker volume ls: Check what volumes exist
  4. rm-force

    Medium

    docker-compose rm -f forcibly removes containers without confirmation.

    Explanation
    The -f/--force flag removes containers without asking for confirmation. While this doesn't directly cause data loss, it can be risky: - Running containers are stopped abruptly (SIGKILL) - No graceful shutdown for applications - In-flight requests or transactions may be lost Safer alternatives: - docker-compose stop: Graceful shutdown first - docker-compose rm: Asks for confirmation - docker-compose ps: Check container status first

Safe patterns

Checked first. A command that matches one is never blocked by this pack.

  • compose-config
  • compose-ps
  • compose-logs
  • compose-up
  • compose-build
  • compose-pull
  • compose-down-no-volumes