fix(deploy): migrate stays healthy instead of exiting (Dokploy) - #105
Merged
Merged
Conversation
The migrate service was a one-shot that exited 0 after applying migrations. Dokploy's Compose orchestration treats an exited init container as the deploy state and doesn't reliably start services that depend on it via `service_completed_successfully` — so web/admin never came up and the only logs/status were migrate's "exited". Now migrate applies migrations, writes /tmp/migrated, then idles (`tail -f /dev/null`) so it stays a running, healthy container. web/admin depend on its healthcheck (`test -f /tmp/migrated`) instead of on completion. Nothing exits; dependents start once migrations are done. On migration failure the `&&` chain aborts and `restart: unless-stopped` retries. Verified locally: built the migrate image, ran it against Postgres — migrations applied, marker written, container stays Up, schema created. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Symptom
After deploy the only logs were the
migratecontainer's (migrations applied successfully) and Dokploy showed the service as exited — web/admin never started.Cause
migratewas a one-shot (restart: "no") that exits 0 when done. Dokploy's Compose handling treats an exited init container as the deployment result and doesn't reliably honordepends_on: service_completed_successfully, so the services that depend on migrate never start.Fix
migratenow: applies migrations →touch /tmp/migrated→tail -f /dev/null(idles, stays running). It gets a healthcheck (test -f /tmp/migrated), and web/admin depend onservice_healthyinstead ofservice_completed_successfully. Nothing exits; dependents start as soon as migrations finish. Migration failure aborts the chain andrestart: unless-stoppedretries.Verified locally
Built
docker/Dockerfile.migrate, ran it against a Postgres scratch DB:migrations applied successfully,[migrate] applied; idling, marker present, containerUp, all tables created.docker compose configvalid.🤖 Generated with Claude Code