{"id":22331073,"url":"https://github.com/rodrigobdz/docker-compose-healthchecks","last_synced_at":"2025-07-04T03:06:08.613Z","repository":{"id":43876644,"uuid":"326459110","full_name":"rodrigobdz/docker-compose-healthchecks","owner":"rodrigobdz","description":"Collection of Docker Compose healthcheck examples. Tested with Docker Compose version 3.8","archived":false,"fork":false,"pushed_at":"2024-09-23T13:40:23.000Z","size":11,"stargazers_count":123,"open_issues_count":0,"forks_count":6,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-06-07T03:03:29.583Z","etag":null,"topics":["bash-script","docker","docker-compose","docker-compose-healthchecks","healthcheck","postgres","shell-script"],"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/rodrigobdz.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-01-03T17:10:14.000Z","updated_at":"2025-06-05T06:24:48.000Z","dependencies_parsed_at":"2025-01-15T03:54:13.377Z","dependency_job_id":"082a015f-0205-4bbc-8b13-0633740afd0f","html_url":"https://github.com/rodrigobdz/docker-compose-healthchecks","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rodrigobdz/docker-compose-healthchecks","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rodrigobdz%2Fdocker-compose-healthchecks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rodrigobdz%2Fdocker-compose-healthchecks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rodrigobdz%2Fdocker-compose-healthchecks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rodrigobdz%2Fdocker-compose-healthchecks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rodrigobdz","download_url":"https://codeload.github.com/rodrigobdz/docker-compose-healthchecks/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rodrigobdz%2Fdocker-compose-healthchecks/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263437339,"owners_count":23466366,"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":["bash-script","docker","docker-compose","docker-compose-healthchecks","healthcheck","postgres","shell-script"],"created_at":"2024-12-04T04:09:34.732Z","updated_at":"2025-07-04T03:06:08.589Z","avatar_url":"https://github.com/rodrigobdz.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Docker Compose Healthchecks\n\n\u003e Collection of Docker Compose `healthcheck` examples\n\n## Collection\n\n### Postgres\n\n```yml\nhealthcheck:\n  test: [\"CMD-SHELL\", \"pg_isready -U postgres\"]\n  interval: 30s\n  timeout: 30s\n  retries: 3\n```\n\n[Source](https://til.codes/health-check-option-in-docker-to-wait-for-dependent-containers-to-be-healthy/)\n\n### Redis\n\n```yml\nredis:\n  image: redis\n  healthcheck:\n    test: [\"CMD\", \"redis-cli\", \"ping\"]\n    interval: 1s\n    timeout: 3s\n    retries: 30\n```\n\n[Source](https://gist.github.com/phuysmans/4f67a7fa1b0c6809a86f014694ac6c3a)\n\n### Elasticsearch\n\n```yml\nhealthcheck:\n  test: curl --silent http://localhost:9200 \u003e/dev/null; if [[ $$? == 52 ]]; then echo 0; else echo 1; fi\n  interval: 30s\n  timeout: 10s\n  retries: 5\n```\n\n[Source](https://www.elastic.co/guide/en/elastic-stack-get-started/current/get-started-docker.html)\n\n### Minio RELEASE.2023-11-01T18-37-25Z and older\n\n```yml\nhealthcheck:\n  test: timeout 5s bash -c ':\u003e /dev/tcp/127.0.0.1/9000' || exit 1\n  start_period: 5s\n  interval: 10s\n  timeout: 5s\n  retries: 2\n```\n\nSource [[1]](https://github.com/minio/minio/issues/18373)\n\n### Minio RELEASE.2023-10-25T06-33-25Z and earlier\n\n```yml\nhealthcheck:\n  test: [\"CMD\", \"curl\", \"-f\", \"http://localhost:9000/minio/health/live\"]\n  interval: 30s\n  timeout: 20s\n  retries: 3\n```\n\nSource [[1]](https://github.com/minio/minio/blob/c9d502e6fadf2c2cbb1e2ce7a9dc8de7dfed1d34/docs/orchestration/docker-swarm/docker-compose-secrets.yaml#L25-L29) [[2]](https://github.com/minio/minio/blob/bdd094bc39275a0543484c09f4fb99ce3fe14787/docs/metrics/healthcheck/README.md)\n\n### Mongo\n\nNote: `mongosh` may need to be used rather than `mongo`, depending on which image you're using.\n\n```yml\nhealthcheck:\n  test:\n    [\n      \"CMD\",\n      \"mongo\",\n      \"--quiet\",\n      \"127.0.0.1/test\",\n      \"--eval\",\n      \"'quit(db.runCommand({ ping: 1 }).ok ? 0 : 2)'\",\n    ]\n  interval: 10s\n  timeout: 10s\n  retries: 5\n  start_period: 40s\n```\n\n## Scripting\n\nTo wait for a Docker container until its health state is `healthy` before executing a command inside the container, use the following function in a shell script:\n\n```sh\nreadonly DOCKER_CONTAINER='my_postgres'\n\nwait_until_container_healthy() {\n  until\n    [ \"$(docker inspect --format \"{{.State.Health.Status}}\" \"$DOCKER_CONTAINER\")\" = 'healthy' ]\n  do\n    # Log container status\n    local container_status\n    container_status=\"$(docker inspect --format \"{{.State.Health.Status}}\" \"$DOCKER_CONTAINER\")\"\n\n    echo \"Waiting for container $DOCKER_CONTAINER to be 'healthy', current status is '$container_status'. Sleeping for five seconds...\"\n    sleep 5\n  done\n}\n```\n\nThis snippet is an improved version of [this](https://stackoverflow.com/a/33520390/2227405) StackOverflow answer.\n\n## Related\n\n- [`docker/awesome-compose`](https://github.com/docker/awesome-compose) - Official Docker Compose examples (includes healthchecks)\n- [`docker-library/healthcheck`](https://github.com/docker-library/healthcheck) - Examples for Dockerfiles\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frodrigobdz%2Fdocker-compose-healthchecks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frodrigobdz%2Fdocker-compose-healthchecks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frodrigobdz%2Fdocker-compose-healthchecks/lists"}