Created
August 30, 2022 17:32
-
-
Save InBrewJ/7eba7471ac0103a78dde9bf865109add to your computer and use it in GitHub Desktop.
Checking PostgreSQL health for dependent services in docker-compose (for e.g. Grafana)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x-pg-healthcheck: &pg-healthcheck | |
healthcheck: | |
test: ["CMD-SHELL", "pg_isready -U postgres"] | |
interval: 5s | |
timeout: 5s | |
retries: 5 | |
x-pg-config: &shared-pg-config | |
image: postgres:13.0-alpine | |
restart: 'unless-stopped' | |
version: '3.8' | |
services: | |
postgres: | |
<<: *shared-pg-config | |
ports: | |
- '5432:5432' | |
environment: | |
POSTGRES_DB: grafana | |
POSTGRES_USER: postgres | |
POSTGRES_PASSWORD: postgres-changeme | |
volumes: | |
- ./data/postgres-grafana:/var/lib/postgresql/data:delegated | |
<<: *pg-healthcheck | |
ev-warehouse: | |
<<: *shared-pg-config | |
ports: | |
- '5433:5432' | |
environment: | |
POSTGRES_DB: ev-analytics-warehouse | |
POSTGRES_USER: postgres | |
POSTGRES_PASSWORD: postgres-changeme | |
volumes: | |
- ./data/postgres-ev-warehouse:/var/lib/postgresql/data:delegated | |
<<: *pg-healthcheck | |
grafana: | |
build: . | |
restart: 'unless-stopped' | |
ports: | |
- '3000:3000' | |
environment: | |
DB_HOST: postgres:5432 | |
DB_NAME: grafana | |
DB_USER: postgres | |
DB_PASS: postgres-changeme | |
WAREHOUSE_DB_HOST: ev-warehouse:5432 | |
WAREHOUSE_DB_NAME: ev-analytics-warehouse | |
WAREHOUSE_DB_USER: postgres | |
WAREHOUSE_DB_PASS: postgres-changeme | |
depends_on: | |
postgres: | |
condition: service_healthy | |
ev-warehouse: | |
condition: service_healthy | |
links: | |
- postgres |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment