PostgreSQL

Run a production-ready PostgreSQL database with Docker Compose in seconds. Includes persistent storage, secure credentials via .env, and a clean setup for local development and self-hosted apps.

yaml

docker-compose.yml

services:
  postgres:
    image: postgres:16-alpine
    restart: unless-stopped
    environment:
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: ${POSTGRES_DB}
    ports:
      - ${POSTGRES_PORT}:5432
    volumes:
      - postgres_data:/var/lib/postgresql/data
volumes:
  postgres_data:

.ENV

.env example

POSTGRES_USER=appuser
POSTGRES_PASSWORD=changeme123
POSTGRES_DB=appdb
POSTGRES_PORT=5432

deployment

Quick Start

  1. Create a working directory named after the service.
  2. Copy the compose file and generated `.env` into that directory.
  3. Review the variables and replace placeholders with real values.
  4. Run `docker compose up -d`.
mkdir postgres
cd postgres
# create docker-compose.yml
# create .env
docker compose up -d