All Projects → peter-evans → Docker Compose Healthcheck

peter-evans / Docker Compose Healthcheck

Licence: mit
How to wait for container X before starting Y using docker-compose healthcheck

Projects that are alternatives of or similar to Docker Compose Healthcheck

Kongpose
Kong and Konga (admin webapp) development setup on docker-compose
Stars: ✭ 52 (-82.19%)
Mutual labels:  postgresql, kong, docker-compose
Uranus
Hierarchical Memo & Task Web-App
Stars: ✭ 71 (-75.68%)
Mutual labels:  postgresql, docker-compose
Fastapi Realworld Example App
Backend logic implementation for https://github.com/gothinkster/realworld with awesome FastAPI
Stars: ✭ 911 (+211.99%)
Mutual labels:  postgresql, docker-compose
Splits Io
a speedrunning data store, analysis engine, and racing platform
Stars: ✭ 99 (-66.1%)
Mutual labels:  postgresql, docker-compose
Filterlists
🛡 The independent, comprehensive directory of filter and host lists for advertisements, trackers, malware, and annoyances.
Stars: ✭ 653 (+123.63%)
Mutual labels:  postgresql, docker-compose
Nodock
Docker Compose for Node projects with Node, MySQL, Redis, MongoDB, NGINX, Apache2, Memcached, Certbot and RabbitMQ images
Stars: ✭ 734 (+151.37%)
Mutual labels:  postgresql, docker-compose
Python Microservice Fastapi
Learn to build your own microservice using Python and FastAPI
Stars: ✭ 96 (-67.12%)
Mutual labels:  postgresql, docker-compose
Enferno
A Python framework based on Flask microframework, with batteries included, and best practices in mind.
Stars: ✭ 385 (+31.85%)
Mutual labels:  postgresql, docker-compose
Express Postgres Starter
A starter project for Node.js with Express and Postgres running on Docker Compose
Stars: ✭ 107 (-63.36%)
Mutual labels:  postgresql, docker-compose
Docker Nginx Postgres Django Example
Example using Docker, Django, multiple Postgres databases, NginX, Gunicorn, pipenv, GitLab CI and tox.
Stars: ✭ 110 (-62.33%)
Mutual labels:  postgresql, docker-compose
Dckerize
Supercharged Rails development using Docker containers
Stars: ✭ 112 (-61.64%)
Mutual labels:  postgresql, docker-compose
Phpmyfaq
phpMyFAQ - Open Source FAQ web application for PHP and MySQL, PostgreSQL and other databases
Stars: ✭ 494 (+69.18%)
Mutual labels:  postgresql, docker-compose
Compose Postgres
Postgresql & pgadmin4 powered by compose
Stars: ✭ 477 (+63.36%)
Mutual labels:  postgresql, docker-compose
Django React Boilerplate
DIY Django + React Boilerplate for starting your SaaS
Stars: ✭ 385 (+31.85%)
Mutual labels:  postgresql, docker-compose
Rails React Typescript Docker Example
An example app built on Ruby on Rails 6.1 + React.js 17 + TypeScript 4.2 + Docker Compose
Stars: ✭ 129 (-55.82%)
Mutual labels:  postgresql, docker-compose
Open Bank Mark
A bank simulation application using mainly Clojure, which can be used to end-to-end test and show some graphs.
Stars: ✭ 81 (-72.26%)
Mutual labels:  postgresql, docker-compose
Devilbox
A modern Docker LAMP stack and MEAN stack for local development
Stars: ✭ 3,598 (+1132.19%)
Mutual labels:  postgresql, docker-compose
Docker Laravel
🐳 Docker Images for Laravel development
Stars: ✭ 101 (-65.41%)
Mutual labels:  postgresql, docker-compose
Symfony 4 Docker Env
Docker Environment for Symfony. PHP-FPM, NGINX SSL Proxy, MySQL, LEMP
Stars: ✭ 119 (-59.25%)
Mutual labels:  postgresql, docker-compose
Godorp
GoDoRP (Golang, Docker, React, Postgres)
Stars: ✭ 191 (-34.59%)
Mutual labels:  postgresql, docker-compose

docker-compose-healthcheck The blog of Peter Evans: How to Wait for Container X Before Starting Y

Actions Status

The healthcheck property was originally introduced in the 2.1 Compose file format and is now part of the Compose Specification used by recent versions of Docker Compose. This allows a check to be configured in order to determine whether or not containers for a service are "healthy."

How can I wait for container X before starting Y?

This is a common problem and in earlier versions of docker-compose requires the use of additional tools and scripts such as wait-for-it and dockerize. Using the healthcheck parameter the use of these additional tools and scripts is often no longer necessary.

Waiting for PostgreSQL to be "healthy"

A particularly common use case is a service that depends on a database, such as PostgreSQL. We can configure docker-compose to wait for the PostgreSQL container to startup and be ready to accept requests before continuing.

The 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.

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

If the check is successful the container will be marked as healthy. Until then it will remain in an unhealthy state. For more details about the healthcheck parameters interval, timeout and retries see the documentation here.

Services that depend on PostgreSQL can then be configured with the depends_on parameter as follows:

depends_on:
  postgres-database:
    condition: service_healthy

Waiting for PostgreSQL before starting Kong

In this complete example docker-compose waits for the PostgreSQL service to be "healthy" before starting Kong, an open-source API gateway. It also waits for an additional ephemeral container to complete Kong's database migration process.

Test it out with:

docker-compose up -d

Wait until all services are running:

Demo

Test by querying Kong's admin endpoint:

curl http://localhost:8001/

License

MIT License - see the LICENSE file for details

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].