A Dockerfile turns a Python application into a reproducible container image that can boot consistently on a laptop, Azure App Service, or another host. Production readiness also requires moving chat history to external storage and keeping secrets outside the image. section 5.1 section 5.1.5
A practical Dockerfile establishes the runtime, dependencies, application files, network hint, and startup command:
- Start from python:3.11-slim to reduce unnecessary image contents while pinning the Python version used by tested packages. section 5.1.5
- Install libgomp1 because scikit-learn may rely on OpenMP even when application code does not call it directly. section 5.1 section 5.1.5
- Set /app as the working directory, copy the source tree there, and install the pinned packages from requirements.txt. section 5.1.5
- Expose port 8000 as the listening-port hint for the hosting platform, then start the application with python app.py. section 5.1.5
- Add .env to .dockerignore so credentials remain outside the image and the same artifact can be shared or scanned safely. section 5.1.5
Listing 5.4 Creating the Dockerfile
FROM python:3.11-slim RUN apt-get update && apt-get install -y libgomp1 && rm -rf /var/lib/apt/lists/* #A WORKDIR /app COPY . /app RUN pip install --upgrade pip && pip install --no-cache-dir -r requirements.txt #B EXPOSE 8000 #C CMD ["python", "app.py"] #D
Use the complete Dockerfile listing to inspect the build order and the rationale-bearing directives that assemble and launch the image. section 5.1.5
Build and run the image
Build from the current directory with docker build --no-cache -t ch5-image ., then run it with docker run -it --env-file .env -p 8000:8000 --name ch5-container ch5-image. section 5.1.5




















