Caio Henrique
07/21/2025, 2:39 PMMarvin
07/21/2025, 2:39 PMMarvin
07/21/2025, 2:41 PMdockerfile
# Use an official Python runtime as the base image
FROM python:3.9-slim
# Set working directory in the container
WORKDIR /app
# Install git and any required system dependencies
# Then clean up apt cache to keep the image size down
RUN apt-get update && \
apt-get install -y git && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Install Prefect
RUN pip install -U prefect
# If you have additional dependencies, you can:
# 1. Either copy and install requirements.txt:
# COPY requirements.txt .
# RUN pip install -r requirements.txt
# 2. Or install them directly:
# RUN pip install pandas scikit-learn
# The actual flow code will be fetched at runtime from your Git repository
# No need to copy flow code into the image
# Set environment variables if needed
# ENV PREFECT_API_URL="<http://your-prefect-server:4200/api>"
# The entrypoint will be handled by Prefect's Docker work pool
# You don't need to specify CMD or ENTRYPOINT
This Dockerfile provides a clean base for running your Prefect flows. Here's how it works:
1. Uses python:3.9-slim
as the base image to keep the image size minimal while providing a full Python environment
2. Installs git
which is required to fetch your flow code from the repository
3. Installs Prefect and any additional dependencies your flows might need
4. Keeps the image generic, as the actual flow code will be fetched at runtime from your Git repository
To use this Dockerfile with your deployment:
1. Save this Dockerfile in your project directory
2. Build the Docker image:
bash
docker build -t your-prefect-image .
3. When creating your deployment, you can reference this image. Here's a Python example of how to create the deployment:
python
from prefect import flow
from prefect.deployments import Deployment
@flow
def my_flow():
print("Hello from the flow!")
deployment = flow.from_source(
source="<https://github.com/your-username/your-repo>",
entrypoint="path/to/flow.py:my_flow"
).deploy(
name="my-flow-deployment",
work_pool_name="your-docker-pool",
image="your-prefect-image:latest"
)
Key points to remember:
1. The Dockerfile should include all system-level dependencies your flows need
2. Your Python package dependencies can either be:
- Installed directly in the Dockerfile
- Listed in a requirements.txt file
- Specified in your deployment configuration
3. The actual flow code doesn't need to be in the image as it will be fetched from Git at runtime
4. Make sure your Docker work pool has access to both:
- Your Docker image (either from a registry or locally)
- Your Git repository
For more detailed information about Docker deployments, you can refer to the Prefect documentation on Docker infrastructure.
Would you like me to explain any specific part of this setup in more detail?