Skip to content

Instantly share code, notes, and snippets.

@zhunik
Created September 14, 2018 15:12
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save zhunik/3f3087d5982bcf0297ab23ebaeb46bc1 to your computer and use it in GitHub Desktop.
Save zhunik/3f3087d5982bcf0297ab23ebaeb46bc1 to your computer and use it in GitHub Desktop.
docker-compose Postgres health-check
version: "3"
services:
postgress:
....
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 10s
timeout: 5s
retries: 5
app:
...
depends_on:
postgres:
condition: service_healthy
@wouerner
Copy link

Thanks!

@ratijas
Copy link

ratijas commented Jan 26, 2020

Gives me this error:

ERROR: The Compose file './docker-compose.yml' is invalid because:
services.app.depends_on contains an invalid type, it should be an array

@zhunik
Copy link
Author

zhunik commented Jan 28, 2020

Gives me this error:

ERROR: The Compose file './docker-compose.yml' is invalid because:
services.app.depends_on contains an invalid type, it should be an array

Seems like this approach is no longer valid. Since docker-compose changed it's behavior with depends_on in latest updates.

Version 3 no longer supports the `condition` form of `depends_on`.

more about this you can find here: -> https://docs.docker.com/compose/compose-file/#depends_on

There is a new approach with wait-for-it.sh script.

More about it here: https://docs.docker.com/compose/startup-order/

@syunwei
Copy link

syunwei commented May 3, 2021

Thank you zhunik very much!!! :)
For other people who want to know more about the command, please visit postgres documentation

@cascading-jox
Copy link

Thanks! Worth noting is that pg_isready with just user specified will check against the db called the same as the username.

@avandrevitor
Copy link

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment