Vincent LEGENDRE
07/23/2025, 9:16 AMMarvin
07/23/2025, 9:16 AMMarvin
07/23/2025, 9:18 AMdockerfile
# Use Python 3.11 slim as base image for smaller size
FROM python:3.11-slim
# Set working directory
WORKDIR /app
# Install system dependencies and clean up in the same layer
RUN apt-get update && apt-get install -y \
gcc \
git \
curl \
&& rm -rf /var/lib/apt/lists/*
# Install poetry
RUN curl -sSL <https://install.python-poetry.org> | python3 -
# Copy poetry files
COPY pyproject.toml poetry.lock ./
# Configure poetry to not create virtual environment (unnecessary in Docker)
RUN poetry config virtualenvs.create false
# Install dependencies
RUN poetry install --no-dev --no-interaction --no-ansi
# Copy your flow code
COPY flows/ ./flows/
# Install Prefect
RUN poetry add prefect
# The default command that will be run when the container starts
CMD ["prefect", "worker", "start", "-p", "k8s-pool"]
Here's a breakdown of what this Dockerfile does:
1. Uses Python 3.11 slim as the base image to keep the image size small
2. Sets up essential system dependencies
3. Installs Poetry for dependency management
4. Configures Poetry to not create virtual environments (unnecessary in containers)
5. Installs your project dependencies from pyproject.toml
and poetry.lock
6. Installs Prefect
7. Sets up the default command to start the Prefect worker
To use this template:
1. Make sure you have these files in your project directory:
- pyproject.toml
- poetry.lock
- A flows
directory containing your Prefect flows
2. You can customize the packages installed by:
- Adding dependencies to your pyproject.toml
using poetry add package-name
- Or modifying the Dockerfile to install additional system packages in the apt-get install
section
3. Build the image:
bash
docker build -t your-prefect-worker:tag .
Some important tips:
1. Adjust the Python version in the first line if you need a different version
2. Add any additional system dependencies you need in the apt-get install
section
3. If you have private dependencies, you might need to add SSH keys or authentication tokens
4. Consider using multi-stage builds for even smaller images if needed
5. You might want to add additional environment variables or configurations specific to your Kubernetes setup
Would you like me to provide any specific modifications to this template based on your needs? For example:
- Additional system packages
- Different Python version
- Specific Poetry configurations
- Custom worker start commandsVincent LEGENDRE
07/23/2025, 9:22 AMMarvin
07/23/2025, 9:22 AMMarvin
07/23/2025, 9:23 AMdockerfile
FROM python:3.11-slim
RUN pip install prefect
# If you have additional packages, add them here
# RUN pip install your-package-name
That's it! This is literally the simplest possible setup that will work. It:
1. Uses a slim Python image as base
2. Installs Prefect
If you're using Poetry, here's the equally minimal version:
dockerfile
FROM python:3.11-slim
COPY pyproject.toml poetry.lock ./
RUN pip install poetry && \
poetry config virtualenvs.create false && \
poetry install --no-dev
Some optional but recommended additions you might want to consider:
1. Add a WORKDIR if you want to organize your files:
dockerfile
WORKDIR /app
2. If you have additional dependencies, you can add them directly:
dockerfile
RUN pip install prefect pandas numpy
3. If you have a requirements.txt:
dockerfile
COPY requirements.txt .
RUN pip install -r requirements.txt
The beauty of this minimal setup is that it provides just what you need for a Prefect flow runtime environment. Since you're using this as a runtime (not a worker), you don't need to specify any CMD or ENTRYPOINT - Prefect will handle the execution of your flows.
Would you like me to expand on any part of this or add any specific packages to the minimal setup?