Slackbot
09/19/2024, 6:20 AMMarvin
09/19/2024, 6:21 AMdocker-compose.yml
file. Below is a basic example for both Prefect 2.x and 3.x:
yaml
version: '3.8'
services:
prefect:
image: prefecthq/prefect:2-latest // for Prefect 3.x use 3-latest
environment:
- PREFECT_API_URL=<http://localhost:4200/api>
- PREFECT_API_KEY=your_api_key
ports:
- "4200:4200"
volumes:
- ~/.prefect:/root/.prefect
Make sure you replace your_api_key
with an actual Prefect API key.
2. Build and Start Services:
Run the following command to build and start the services defined in the Docker Compose file:
sh
docker-compose up -d
3. Check the Prefect Server:
Verify that the Prefect server is running by navigating to <http://localhost:4200>
.
### Managing Flows
For managing flows, you should follow different procedures depending on your Prefect version.
1. Prefect 2.x:
- Creating a Flow:
Define your flow in a Python script:
python
from prefect import flow, task
@task
def my_task():
print("Hello from my task!")
@flow
def my_flow():
my_task()
if __name__ == "__main__":
my_flow()
- Running the Flow:
You can run the script directly or use Prefect CLI to interact with it.
sh
prefect deployment build -n my-deployment-script.py
2. Prefect 3.x:
- Creating a Work Pool and Worker:
sh
prefect work-pool create --type docker my-docker-pool
- Starting a Worker:
In a new terminal, start the worker:
sh
prefect worker start --pool my-docker-pool
- Defining and Running the Flow:
Similar to Prefect 2.x, define your flow in a Python script and run it.
### Additional Resources and Troubleshooting
For complete guides and troubleshooting, refer to the Prefect documentation and GitHub issues:
- Prefect 2.x Docker Guide
- Prefect 3.x Docker Guide
- Self-hosted Prefect 3.x
- GitHub Issue on Docker Installation
By following these steps and referring to the documentation, you should be able to set up and manage Prefect on a local server using Docker Compose effectively.