Kevin
05/13/2024, 9:40 PMMarvin
05/13/2024, 9:40 PMDockerfile
that specifies the Python version you want, copies your flow file, and installs any dependencies your flow might need.
2. Build a Docker image using your Dockerfile
.
3. (Optional) Use Prefect's DeploymentImage
class to define your image for deployment.
4. Run the Docker container with the appropriate environment variables set, such as PREFECT_API_URL
, which should point to your self-hosted Prefect API instance.
Here's an example of the Dockerfile
you would write:
Dockerfile
FROM python:3.10
COPY ./requirements.txt /requirements.txt
RUN pip install -r /requirements.txt
And then run commands like:
bash
docker build -t my-flow-image:latest .
docker run -e PREFECT_API_URL=<http://host.docker.internal:4200/api> my-flow-image:latest
Remember to replace <http://host.docker.internal:4200/api>
with the URL of your Prefect API. Also, if you're using Linux, you'll need to use your machine's IP address instead of host.docker.internal
.
For a detailed guide on deploying your flow with Docker, consult the Prefect Docker Guide.
If you decide to create a deployment manifest and use Kubernetes for orchestration, you would define your flow image and other Kubernetes specifications in a .yaml
file. An example deployment command using kubectl
would be:
bash
kubectl apply -f deployment-manifest.yaml
For more advanced Docker image specifications when deploying your flow, you can use the optional keyword arguments for the DeploymentImage
class provided by Prefect. To set a default Docker namespace for your images, you can also update your Prefect configuration:
bash
prefect config set PREFECT_DEFAULT_DOCKER_BUILD_NAMESPACE=<docker-registry-url>/<organization-or-username>
Please refer to this guideline for creating a deployment by leveraging the `DeploymentImage` class.