{"id":13584548,"url":"https://github.com/peter-evans/docker-compose-healthcheck","last_synced_at":"2025-04-04T16:13:57.666Z","repository":{"id":37677879,"uuid":"83654982","full_name":"peter-evans/docker-compose-healthcheck","owner":"peter-evans","description":"How to wait for container X before starting Y using docker-compose healthcheck","archived":false,"fork":false,"pushed_at":"2022-02-15T04:24:42.000Z","size":616,"stargazers_count":752,"open_issues_count":6,"forks_count":59,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-03-28T15:08:18.468Z","etag":null,"topics":["docker","docker-compose","health-check","healthcheck","kong","postgresql"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/peter-evans.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-02T08:41:55.000Z","updated_at":"2025-03-20T23:31:32.000Z","dependencies_parsed_at":"2022-08-08T21:15:47.601Z","dependency_job_id":null,"html_url":"https://github.com/peter-evans/docker-compose-healthcheck","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peter-evans%2Fdocker-compose-healthcheck","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peter-evans%2Fdocker-compose-healthcheck/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peter-evans%2Fdocker-compose-healthcheck/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peter-evans%2Fdocker-compose-healthcheck/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peter-evans","download_url":"https://codeload.github.com/peter-evans/docker-compose-healthcheck/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247208143,"owners_count":20901570,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","docker-compose","health-check","healthcheck","kong","postgresql"],"created_at":"2024-08-01T15:04:20.057Z","updated_at":"2025-04-04T16:13:57.648Z","avatar_url":"https://github.com/peter-evans.png","language":null,"funding_links":[],"categories":["Others"],"sub_categories":[],"readme":"# docker-compose-healthcheck [\u003cimg align=\"right\" alt=\"The blog of Peter Evans: How to Wait for Container X Before Starting Y\" title=\"View blog post\" src=\"https://peterevans.dev/img/blog-published-badge.svg\"\u003e](https://peterevans.dev/posts/how-to-wait-for-container-x-before-starting-y/)\n[![Actions Status](https://github.com/peter-evans/docker-compose-healthcheck/workflows/docker-compose-healthcheck/badge.svg)](https://github.com/peter-evans/docker-compose-healthcheck/actions)\n\nThe [healthcheck](https://docs.docker.com/compose/compose-file/compose-file-v2/#healthcheck) property was originally introduced in the 2.1 Compose file format and is now part of the [Compose Specification](https://github.com/compose-spec/compose-spec/blob/master/spec.md) used by recent versions of Docker Compose.\nThis allows a check to be configured in order to determine whether or not containers for a service are \"healthy.\"\n\n## How can I wait for container X before starting Y?\n\nThis is a common problem and in earlier versions of docker-compose requires the use of additional tools and scripts such as [wait-for-it](https://github.com/vishnubob/wait-for-it) and [dockerize](https://github.com/jwilder/dockerize).\nUsing the `healthcheck` parameter the use of these additional tools and scripts is often no longer necessary.\n\n## Waiting for PostgreSQL to be \"healthy\"\n\nA particularly common use case is a service that depends on a database, such as PostgreSQL.\nWe can configure docker-compose to wait for the PostgreSQL container to startup and be ready to accept requests before continuing.\n\nThe following healthcheck has been configured to periodically check if PostgreSQL is ready using the `pg_isready` command. See the documentation for the `pg_isready` command [here](https://www.postgresql.org/docs/9.4/static/app-pg-isready.html).\n```yml\nhealthcheck:\n  test: [\"CMD-SHELL\", \"pg_isready\"]\n  interval: 10s\n  timeout: 5s\n  retries: 5\n```\nIf the check is successful the container will be marked as `healthy`. Until then it will remain in an `unhealthy` state.\nFor more details about the healthcheck parameters `interval`, `timeout` and `retries` see the documentation [here](https://docs.docker.com/engine/reference/builder/#healthcheck).\n\nServices that depend on PostgreSQL can then be configured with the `depends_on` parameter as follows:\n```yml\ndepends_on:\n  postgres-database:\n    condition: service_healthy\n```\n\n## Waiting for PostgreSQL before starting Kong\n\nIn [this complete example](docker-compose.yml) docker-compose waits for the PostgreSQL service to be \"healthy\" before starting [Kong](https://getkong.org/), an open-source API gateway. It also waits for an additional ephemeral container to complete Kong's database migration process.\n\nTest it out with:\n```\ndocker-compose up -d\n```\nWait until all services are running:\n\n![Demo](/demo.gif?raw=true)\n\nTest by querying Kong's admin endpoint:\n```\ncurl http://localhost:8001/\n```\n\n## License\n\nMIT License - see the [LICENSE](LICENSE) file for details\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeter-evans%2Fdocker-compose-healthcheck","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeter-evans%2Fdocker-compose-healthcheck","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeter-evans%2Fdocker-compose-healthcheck/lists"}