Skip to content
Stuff I'm Up To
Go back

docker-compose healthcheck

Updated:
Edit page

Here I’m building a library of health checks used for various docker-compose containers.

MySQL / MariaDB

    healthcheck:
      test: [ 'CMD', 'mysqladmin', 'ping', '-u', 'root', '-p${MYSQL_ROOT_PASSWORD?REQUIRED}' ]
      interval: 1m
      timeout: 10s
      retries: 5

redis

    healthcheck:
      test: [ 'CMD', 'redis-cli', 'ping' ]
      interval: 5m
      timeout: 10s
      retries: 5

PostgreSQL

pg_isready isn’t really useful because often the service can be up, but the db isn’t available.

    healthcheck:
      test: [ "CMD", "psql", "-U", "postgres", "-c", "SELECT 1;" ]
      interval: 1m
      timeout: 10s
      retries: 5

curl

Ensure you use --fail or your health check will always succeed.

    healthcheck: 
      test: [ "CMD", "curl", "--fail", "http://localhost" ]
      interval: "60s"
      timeout: "5s"
      retries: 3

Edit page
Share this post:

Previous Post
Gnome Background Colours
Next Post
Horizon Client System Lock Up