liveBook · Manning

Dockerfile

As explained in Enterprise RAG

A Dockerfile is a text configuration file containing instructions for building a container image.

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

How Enterprise RAG covers it

How deep it goes
Explains directives line by line, including dependency rationale, build context, startup, ports, and secret exclusion.
Examples
Uses a Python 3.11 image, libgomp1 installation, requirements.txt, port 8000, .env exclusion, and build-run commands.
What it assumes
Assumes a Python project with app.py, requirements.txt, tests, and environment configuration while teaching Dockerfile structure from first principles.
What you can do after
Build it from scratch and run it with pinned dependencies, environment-file injection, port mapping, and a direct Python startup command.
How it connects
Connects container images with dependency pinning, secret management, externalized persistence, and hosting platforms.

Also explained in

Compare how 21 books explain Dockerfile →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Enterprise RAG. The section links point to the parts of the book it draws on.