Docker Compose — PostgreSQL Dev Environment
Full Docker Compose setup for PostgreSQL with pgAdmin, init scripts, volumes, and health checks.
version: '3.9'
services:
postgres:
image: postgres:16-alpine
container_name: dev-postgres
restart: unless-stopped
environment:
POSTGRES_DB: myapp
POSTGRES_USER: devuser
POSTGRES_PASSWORD: ${DB_PASSWORD:-devpass123}
ports:
- '5432:5432'
volumes:
- pgdata:/var/lib/postgresql/data
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
healthcheck:
test: ['CMD-SHELL', 'pg_isready -U devuser -d myapp']
interval: 10s
timeout: 5s
retries: 5
pgadmin:
image: dpage/pgadmin4:latest
container_name: dev-pgadmin
restart: unless-stopped
environment:
PGADMIN_DEFAULT_EMAIL: admin@local.dev
PGADMIN_DEFAULT_PASSWORD: admin
ports:
- '5050:80'
depends_on:
postgres:
condition: service_healthy
volumes:
pgdata:
driver: localSponsored
DigitalOcean
Use Cases
- Local database development environment
- Onboarding new developers with one command
- Integration testing with real PostgreSQL
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
PostgreSQL Docker Setup with Init Script
Docker Compose for PostgreSQL with volume persistence, init scripts, and connection pooling.
Best for: Local PostgreSQL for development
Docker Compose — Multi-Environment Override
Use Docker Compose override files for dev, staging, and production with shared base configuration.
Best for: Shared base config with environment-specific overrides
Docker Compose Profiles — Optional Services
Use Docker Compose profiles to selectively start optional services like monitoring, debugging tools.
Best for: Optional monitoring stack for local development
Database Backup Script with Rotation
Automated PostgreSQL backup script with compression, rotation, and optional S3 upload.
Best for: Automated nightly database backups