KG
11/11/2025, 3:59 PMMarvin
11/11/2025, 3:59 PMMarvin
11/11/2025, 3:59 PMKG
11/11/2025, 4:00 PMMarvin
11/11/2025, 4:00 PMMarvin
11/11/2025, 4:17 PMservices:
postgres:
image: postgres:16
container_name: prefect-postgres
environment:
POSTGRES_USER: prefect
POSTGRES_PASSWORD: prefect
POSTGRES_DB: prefect
volumes:
- prefect-postgres-data:/var/lib/postgresql/data
# Creates pg_trgm on first init of the database
- ./postgres/init.sql:/docker-entrypoint-initdb.d/init.sql:ro
healthcheck:
test: ["CMD-SHELL", "pg_isready -U prefect -d prefect"]
interval: 10s
timeout: 5s
retries: 10
restart: unless-stopped
prefect:
image: prefecthq/prefect:3
container_name: prefect-server
environment:
# Prefect 3 uses asyncpg with Postgres
PREFECT_API_DATABASE_CONNECTION_URL: <postgresql+asyncpg://prefect:prefect@postgres:5432/prefect>
# Bind the API/UI to all interfaces so it’s reachable from your host
PREFECT_SERVER_API_HOST: 0.0.0.0
command: >
bash -lc "prefect server start --host 0.0.0.0 --port 4200"
ports:
- "4200:4200"
depends_on:
postgres:
condition: service_healthy
restart: unless-stopped
volumes:
prefect-postgres-data:
2) postgres/init.sql (ensures pg_trgm is enabled)
CREATE EXTENSION IF NOT EXISTS pg_trgm;
Notes
- Redis is optional in Prefect 3; the server uses an in-memory broker by default. You only need Redis for advanced/high-availability setups.
- Pin the Prefect image to a specific 3.x tag for reproducibility (e.g., prefecthq/prefect:3.x.y-python3.12) if you prefer.
Start and verify
- Start: docker compose up -d
- UI: open http://localhost:4200
- Health: curl <http://localhost:4200/api/health>
Point your Prefect CLI at the local server
prefect config set PREFECT_API_URL="<http://127.0.0.1:4200/api>"
Optional: run flows with a worker
- Create a work pool: prefect work-pool create "local-pool" --type process
- Start a worker that polls it:
prefect worker start -p "local-pool"
Cleanup
- Stop: docker compose down
- Stop and remove data: docker compose down -v (drops the DB volume)
Docs and references
- Self-hosted with Docker Compose: Prefect 3 Docker Compose guide
- Server concepts (incl. pg_trgm requirement): Prefect Server concepts
- Settings reference: Settings reference
If you’re on Prefect 2.x instead, let me know and I’ll adapt the compose file and steps accordingly.