This guide explains how to package your Python policy server into a Docker container, so that it can be run and tested consistently by instructors or TAs.
Your project may look like:
student_repo/
├── serve_policy.py
└── ...other files
Create a file named Dockerfile in the root of your repo:
# Use a proper image
FROM ...
# Set working directory
WORKDIR /app
# Copy the needed files
COPY ...
# Install system dependencies if needed
RUN apt-get update && apt-get install -y \
git \
curl \
&& rm -rf /var/lib/apt/lists/*
# Install Python dependencies
RUN ...
# Default command to run your policy server
CMD ["python", "serve_policy.py"]Make sure your server listens on
0.0.0.0, not127.0.0.1.
Run the following in your project directory:
docker build -t <your-policy-server> .The instructor or TA can run the container and map any host port to the container port:
docker run --rm --gpus all -p 8000:8000 -v $(pwd)/models:/models <your-policy-server> [args for serve_policy.py]- Replace
8000with any desired port. - The server inside the container must listen on
0.0.0.0. - run with GPU support (requires NVIDIA Container Toolkit)
- Provide a Dockerfile in your repository, or a pre-built Docker image file (
.tar). - Make sure your server (
serve_policy.py) listens on 0.0.0.0 so it can accept connections from outside the container. - The image should be runnable by the TA without additional setup.
- Export image as
.tar:
docker save -o your-policy-server.tar your-policy-server- TA can import and run:
docker load -i your-policy-server.tar
docker run ...