Marcelo de Souza
10/01/2024, 11:12 PMMarvin
10/01/2024, 11:12 PMsh
docker run -d --name prefect-postgres -v prefectdb:/var/lib/postgresql/data -p 5432:5432 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=yourTopSecretPassword -e POSTGRES_DB=prefect postgres:latest
2. Create a Docker Compose YAML File: Create a docker-compose.yml
file with the following content:
yaml
version: "3"
services:
db:
image: postgres:latest
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=yourTopSecretPassword
- POSTGRES_DB=prefect
ports:
- "5432:5432"
volumes:
- db:/var/lib/postgresql/data
prefect:
image: prefecthq/prefect:3.0.0-py3.8
command: prefect server start --host 0.0.0.0
environment:
- PREFECT_LOGGING_LEVEL=DEBUG
- PREFECT_API_DATABASE_CONNECTION_URL=<postgresql+asyncpg://postgres:yourTopSecretPassword@db:5432/prefect>
ports:
- "4200:4200"
depends_on:
- db
worker:
image: prefecthq/prefect:3.0.0-py3.8
working_dir: /app
command: python -m your_task_module
volumes:
- .:/app
environment:
- PREFECT_API_URL=<http://prefect:4200/api>
- PREFECT_LOGGING_LEVEL=DEBUG
volumes:
db:
Make sure to replace your_task_module
with the module you want to run.
3. Configure Prefect: Set up your Prefect configuration to point to the new PostgreSQL database and Prefect API URL by running the following commands:
sh
prefect config set PREFECT_API_DATABASE_CONNECTION_URL="<postgresql+asyncpg://postgres:yourTopSecretPassword@localhost:5432/prefect>"
prefect config set PREFECT_API_URL="<http://127.0.0.1:4200/api>"
4. Start Docker Compose: Navigate to the directory containing your docker-compose.yml
file and run:
sh
docker-compose up -d
This will start the PostgreSQL database, Prefect server, and worker services.
For more detailed instructions and further configurations, you can visit the following links:
- Self-Hosting Prefect
- Sample GitHub Issue Discussion