Minimal setup to run Prefect 3 flows with Postgres, Prefect Server/Services, and a worker container that already includes your code and dependencies.
flows/: examples;greetings_flow.pyis the hello-world.prefect.yaml: deployments (cron, params, pool) without external storage; the code is baked into the worker image.Dockerfile: builds the worker image (tag comes fromWORKER_IMAGEin.env).docker-compose.yaml: brings up Prefect Server/Services and Postgres and creates the shared network; the worker is not included here.docker-compose-worker.yaml: brings up only the worker (image and pool driven by.env); use it alongside an existing Prefect API.deploy.bat: builds the worker image, restarts the worker container, syncs deps withuv, points CLI to the local API, ensures the work pool, and runsprefect deploy --all.
- Docker and Docker Compose.
- Python 3.12 with
uv(pip install uv). - Prefect CLI can be global; the script uses
uv run prefect.
- Copy env vars and adjust:
cp .env.example .env
- Start the local stack (Prefect Server/Services + Postgres):
docker compose up -d
- Register deployments and (re)launch the worker with the current image:
./deploy.bat
- Does: build (
WORKER_IMAGE), restartprefect-worker,prefect config set PREFECT_API_URL=..., ensure pool (WORK_POOL_NAME), runprefect deploy --all. - Manual equivalent:
uv run prefect deploy --all
- Does: build (
- Worker only (API already available):
docker compose -f docker-compose-worker.yaml up -dwithPREFECT_API_URLpointing to your server.
- Add flows under
flows/and reference them inprefect.yaml(entrypoint, params). - Rebuild the image when code or deps change (
docker compose build prefect-workeror./deploy.bat). - Pool: image starts
prefect worker start --pool ${WORK_POOL_NAME}; adjust labels/vars via CLI/UI. If you change the pool name, keepWORK_POOL_NAMEin.envandwork_pool.nameinprefect.yamlin sync. - UI: http://localhost:4200 (local compose).
- Worker restart in
deploy.batcan interrupt running flows; add rolling update/health-check or zero-downtime refresh. - Image and deployment versioning (avoid
latest; tag builds and register deployments with the tag used). - CI/CD should handle build/push and
prefect deploy; keep the.batfor local dev only. - Evaluate pulling code/artifacts vs rebuilding the image on every change (performance vs consistency).
- Scaling model: currently one container per worker; validate if multiple workers/replicas per image or higher concurrency on fewer workers is better when many workers are needed.
.prefectignoreexcludes virtualenvs and editor artifacts.- Worker
working_diris/app, aligned to the DockerfileWORKDIR. - Prefect docs: https://docs.prefect.io/v3/get-started