Kitloft

All tools / Docker Compose examples

PostgreSQL with Docker Compose

PostgreSQL with a named volume, a health check and the port published only on localhost.

Customize names, versions and passwords →

compose.yaml
services:
  postgres:
    image: postgres:17
    restart: unless-stopped
    environment:
      POSTGRES_USER: "app"
      POSTGRES_PASSWORD: "change-me"
      POSTGRES_DB: "app"
    volumes:
      - postgres-data:/var/lib/postgresql/data
    ports:
      - "127.0.0.1:5432:5432"
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U app -d app"]
      interval: 10s
      timeout: 5s
      retries: 5

volumes:
  postgres-data:

Passwords here are placeholders (change-me). The generator creates random ones for you.

How to use it

Commands
docker compose up -d
docker compose ps
docker compose logs -f

Prefer Kubernetes? See the PostgreSQL Kubernetes version.