Defines an operational backup task as a profile-gated service.
Section: Production-Minded Compose Patterns
Backup sidecar pattern
yaml
yaml
services:
db:
image: postgres:16
volumes:
- pgdata:/var/lib/postgresql/data
backup:
image: postgres:16
profiles: ["ops"]
depends_on:
- db
entrypoint: ["sh", "-c", "pg_dump -h db -U postgres appdb > /backup/appdb.sql"]
volumes:
- ./backup:/backup
volumes:
pgdata: {}Explanation
Keeps maintenance commands versioned alongside the stack.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing Production-Minded Compose Patterns
App with healthcheck and restart policy
Adds self-healing and health visibility to a service.
Watch files and sync/rebuild
Watches project files and applies sync or rebuild actions when configured.
Validate effective config
Checks whether the Compose config is valid without printing it.