I’m using PostgreSQL in a lot of projects and in my dev environments I always run it with docker-compose. But configuring it properly isn’t so clear if you want to use proper time zone and a health check. Attached the config with a custom database name “db” and an admin user. With this pg_isready
is used in the healthcheck section with proper parameters based on the config. Works perfect for me like this. If you have improvements, please let me know.
version: "3.9"
services:
postgres:
image: postgres:15-alpine
container_name: postgres
hostname: postgres
volumes:
- /etc/localtime:/etc/localtime:ro
- postgres:/var/lib/postgresql/data/pgdata:rw
ports:
- "127.0.0.1:5432:5432"
environment:
POSTGRES_DB: db
POSTGRES_USER: admin
POSTGRES_PASSWORD: admin
PGDATA: /var/lib/postgresql/data/pgdata
TZ: UTC
PGTZ: UTC
healthcheck:
test: [ "CMD-SHELL", "pg_isready -U admin -d db" ]
interval: 1s
timeout: 5s
retries: 10
volumes:
postgres: