This guide provides instructions on how to package your model wrapper service into a Docker container for deployment.
Packaging your service with Docker allows you to create a portable and reproducible environment for your model.
Create a Dockerfile in the root of your project. This file will contain the instructions for building your Docker image. Here is an example Dockerfile from this repository:
FROM python:3.9.19-slim-bullseye
COPY . /app
WORKDIR /app
RUN apt-get update && apt-get install -y redis-server && apt-get clean
RUN pip install -e . && mkdir -p /app/data
ENV ASYNC_ALLOW=True
CMD cd /app/data && redis-server --daemonize yes && python /app/examples/properties/simple_implementation/implementation.pyThis Dockerfile:
- Starts from a Python 3.9 base image.
- Copies the project files into the
/appdirectory in the image. - Sets the working directory to
/app. - Installs Redis.
- Installs the project dependencies.
- Sets the
ASYNC_ALLOWenvironment variable toTrue. - Defines the command to start the Redis server and the model wrapper service.
Once you have created your Dockerfile, you can build the Docker image using the following command:
docker build -t your-image-name:your-tag .Replace your-image-name and your-tag with a name and tag for your image (e.g., my-solubility-predictor:v1).
After building the image, you can run it as a container:
docker run -p 8080:8080 your-image-name:your-tagThis will start your service and map port 8080 on your local machine to port 8080 in the container. You can then access your service at http://localhost:8080.
To use your image in a production environment, you will need to push it to a container registry, such as Docker Hub, Google Container Registry (GCR), or Amazon Elastic Container Registry (ECR).
docker push your-registry/your-image-name:your-tagFor deploying your service to a Kubernetes cluster, we recommend using the OpenAD Model Helm Template. This Helm chart provides a standardized way to deploy OpenAD models to Kubernetes and OpenShift.
Please refer to the documentation in the OpenAD Model Helm Template repository for detailed instructions on how to use the chart.