8000 GitHub - galek/docker-compose-healthchecks: Collection of Docker Compose healthcheck examples. Tested with Docker Compose version 3.8
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

galek/docker-compose-healthchecks

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

Docker Compose Healthchecks

Collection of Docker Compose healthcheck examples

Collection

Postgres

healthcheck:
  test: ["CMD-SHELL", "pg_isready -U postgres"]
  interval: 30s
  timeout: 30s
  retries: 3

Source

Redis

redis:
  image: redis
  healthcheck:
    test: ["CMD", "redis-cli", "ping"]
    interval: 1s
    timeout: 3s
    retries: 30

Source

Elasticsearch

 healthcheck:
  test: curl --silent http://localhost:9200 >/dev/null; if [[ $$? == 52 ]]; then echo 0; else echo 1; fi
  interval: 30s
  timeout: 10s
  retries: 5

Source

Minio

healthcheck:
  test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
  interval: 30s
  timeout: 20s
  retries: 3

Source [1] [2]

Mongo

healthcheck:
  test:
    [
      "CMD",
      "mongo",
      "--quiet",
      "127.0.0.1/test",
      "--eval",
      "'quit(db.runCommand({ ping: 1 }).ok ? 0 : 2)'",
    ]
  interval: 10s
  timeout: 10s
  retries: 5
  start_period: 40s

Scripting

To 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:

readonly DOCKER_CONTAINER='my_postgres'

wait_until_container_healthy() {
  until
    [ "$(docker inspect --format "{{.State.Health.Status}}" "$DOCKER_CONTAINER")" = 'healthy' ]
  do
    # Log container status
    local container_status
    container_status="$(docker inspect --format "{{.State.Health.Status}}" "$DOCKER_CONTAINER")"

    echo "Waiting for container $DOCKER_CONTAINER to be 'healthy', current status is '$container_status'. Sleeping for five seconds..."
    sleep 5
  done
}

This snippet is an improved version of this StackOverflow answer.

Related

About

Collection of Docker Compose healthcheck examples. Tested with Docker Compose version 3.8

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0