What this thread does
Do first: run docker compose config, then give each persistent dependency a named data volume and a healthcheck before adding condition: service_healthy to the app.
Short answer
As of November 2026, use current Docker Compose docs for this Redis-based example; adapt the image, readiness command and data directory to the actual database. Pin image digests for reproducibility. A health gate handles initial admission; the application must also reconnect after later dependency replacement. Service configuration, network lifecycle.
Choose / don't choose
- Named volume: choose Docker-managed database storage that survives container recreation; don't treat it as a backup. Use a database-consistent export and a restore exercise. Volumes.
- Bind mount: choose when host tools must access files directly; don't assume identical host ownership, filesystem or SELinux permissions. Mount only the intended data directory, never the image's application directory. Bind mounts.
- Health gate: choose for dependency readiness; don't equate a running container or successful ping with application migrations being complete.
Not for: interpolation-only failures; see docker-compose-variable-is-not-set-defaulting-to-blank-string-env-file.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
healthcheck.test | ["CMD", "redis-cli", "ping"] | Current Compose; Redis example | Quickstart |
healthcheck.interval / timeout | 5s / 3s, example values, size for the dependency | Current Compose | Quickstart |
healthcheck.retries / start_period | 5 / 10s; failures during startup grace do not count; a success ends grace | Current Compose | Quickstart, health semantics |
services.redis.volumes / top-level volumes | redis-data:/data; declare redis-data: {} under top-level volumes | Current Compose; Redis data directory | Quickstart |
depends_on.redis.condition | service_healthy under the app service | Current Compose | Startup order |
depends_on.redis.restart | true if an explicit Compose dependency update/restart should restart the app too; not automatic runtime crash recovery | Current Compose | Startup order |
Docker's example health values are a starting point, not a universal startup budget. Mounting a populated volume hides image files at that target; empty volumes copy existing target contents by default. Recreate with the corrected mount rather than deleting unknown data. Volume semantics.
Order of operations
1. Build the app image, select dependency image digests and declare the mounts and health settings above. Run docker compose config, then docker compose up -d. Connect the app to the service name redis, not a container IP. Networking. 2. Inspect docker compose ps, docker compose logs redis and docker inspect --format '{{json .State.Health}}' CONTAINER before starting downstream troubleshooting. The health log retains command output and exit status. Health diagnostics. 3. Implement bounded connection retry/reconnect in the application; replacement invalidates old sockets and may change the IP. Resolve the service name again. service_healthy gates the dependent service's startup. Networking. 4. Write disposable data, force the database's durable flush using its own documented mechanism, recreate containers, and read it back.; docker compose down --volumes intentionally removes them. Shutdown.
Known failures and fixes
| Error (short quote) | Cause | Fix | Source |
|---|---|---|---|
unhealthy | Readiness command fails, times out; health status is in addition to normal container status | Read .State.Health output and service logs; run the exact check inside the container; correct command or measured startup budget | Health diagnostics |
unhealthy on a one-off dependency | chrkr reported run inspecting another one-off dependency instead of the healthy regular service | Inspect all matching containers and distinguish run from up; remove obsolete one-off containers after identifying ownership | chrkr, January 7, 2025 |
| Data missing after recreation | Anonymous volume was not reattached, wrong target hides files | Inspect actual mounts; use stable named volume; compare container UID/GID with directory ownership and write permission before changing ownership | Volumes, service user/group |
celinederoland's October 1, 2021 report concerns anonymous-volume removal; it is historical evidence, not a current named-volume guarantee.
Missing
- The linked source does not confirm: executable must exist in the image
- Confirmed: ordinary
docker compose downretains named volumes (source). - The app's database image, required readiness query, data path, operating UID/GID, startup distribution and backup destination are unspecified. Redis
/datamust not be copied blindly to another image.
Checked
2026-11-12; current docs, November 2026. Sources read: Docker service, quickstart, health, volume, bind-mount, startup, networking and shutdown references; chrkr and celinederoland issue reports. No container commands executed.
Started from a post by @Docker, packaged by the editor. Original post