Standalone Prefect server (API + UI only). No flow code, no worker. Use this repo to run the Prefect API and dashboard with a PostgreSQL backend. Workers and clients in another repo connect via PREFECT_API_URL and PREFECT_API_AUTH_STRING.
[This repo: Prefect Server] → PostgreSQL (e.g. shared DB)
↑
| PREFECT_API_URL + PREFECT_API_AUTH_STRING
|
[Worker repo] → runs flows, talks to this server
- Docker (build from the included Dockerfile)
- PostgreSQL instance for Prefect’s database (migrations and run history)
Configure these where the server runs (e.g. Railway Variables).
docker build -t prefect-server .
docker run --rm -p 4200:4200 \
-e PREFECT_API_DATABASE_CONNECTION_URL="postgresql+asyncpg://user:pass@host:5432/prefect" \
-e PREFECT_SERVER_API_AUTH_STRING="admin:password" \
prefect-server- Create a new service from this repo; build from the Dockerfile.
- Set the env vars above (at least
PREFECT_API_DATABASE_CONNECTION_URLandPREFECT_SERVER_API_AUTH_STRING). SetPORTonly if your platform requires it (Railway sets it automatically). - Expose the service (e.g. public domain) so:
- Users can open the Prefect UI in the browser (with Basic Auth).
- The worker service can reach the API (internal URL like
http://<service-name>.railway.internal:4200/apior the public URL +/apiif the worker is elsewhere).
In the repo that runs flows and the Prefect worker:
PREFECT_API_URL— API base URL of this server, e.g.http://<prefect-server-service>.railway.internal:4200/apiorhttps://your-prefect-server.up.railway.app/api.PREFECT_API_AUTH_STRING— Same value as this server’sPREFECT_SERVER_API_AUTH_STRING(e.g.admin:your_secure_password).
No code or config changes are needed in this server repo when you update the worker repo; the server is stateless except for the database.
- Base:
prefecthq/prefect:3-latest - Extra:
asyncpgis installed so the server can use PostgreSQL with SQLAlchemy async. Set the URL aspostgresql+asyncpg://user:password@host:port/database; usingpostgresql://(sync driver) causesThe loaded 'psycopg2' is not async. - Start:
prefect server start --host 0.0.0.0, with port taken fromPREFECT_SERVER_API_PORT(derived fromPORTwhen set by the platform).
