{"name":"docker-compose-postgres","title":"Docker Compose Postgres","description":"A Docker Compose file for Postgres with a persistent volume, a health check and init scripts, plus variants with an app service and pgAdmin.","category":"deploy","updated":"2026-11-08","url":"https://sniptide.com/templates/docker-compose-postgres","files":[{"name":"compose.yaml","language":"yaml","content":"services:\n  db:\n    image: postgres:17\n    restart: unless-stopped\n    environment:\n      POSTGRES_USER: ${POSTGRES_USER:-app}\n      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-app}\n      POSTGRES_DB: ${POSTGRES_DB:-app}\n    ports:\n      - \"127.0.0.1:5432:5432\"\n    volumes:\n      - pgdata:/var/lib/postgresql/data\n      - ./db/init:/docker-entrypoint-initdb.d:ro\n    healthcheck:\n      test: [\"CMD-SHELL\", \"pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}\"]\n      interval: 5s\n      timeout: 5s\n      retries: 10\n\nvolumes:\n  pgdata:\n"}]}