liveBook · Manning

Container image

As explained in Enterprise RAG

A Docker image is an immutable package containing a filesystem, application code, and metadata used to create containers.

A container image packages the exact runtime needed to start a service: application code, Python and system dependencies, startup command, and exposed port. It replaces laptop-specific assumptions with a reproducible artifact that can run unchanged across local machines and hosting environments. section 5.1 section 5.1.5

Build the image from a deliberately bounded project directory. Pin the base Python version and requirements, copy the source into a working directory, install required system libraries and packages, expose the listening port, and define the process Docker starts. Keep mutable data outside the image: a local SQLite file would be reset whenever a new container starts. section 5.1 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
 

This Dockerfile turns the application into a Python 3.11 image, installs libgomp1 and pinned dependencies, advertises port 8000, and starts app.py directly. section 5.1.5

Treat an image as a production contract rather than a zip file:

  • Exclude .env from the build context with .dockerignore. Supply secrets at runtime so a shared or scanned image cannot expose API keys. section 5.1.5
  • Tag and push the tested image to a private container registry. Azure App Service, GitHub Actions, and Kubernetes can then pull the same tagged artifact. section 5.2.1
  • Run tests in the image intended for production. A passing pipeline verifies both application logic and the dependencies included in requirements.txt. section 5.2.4

From local build to hosted service

Build a local image, pass environment variables when running it, then tag and push it to an Azure Container Registry. A Web App can pull that immutable image at startup while configuration supplies secrets separately; GitHub Actions can rebuild, test, and replace the prior container on each successful commit. section 5.1.5 section 5.2 section 5.2.1 section 5.2.4

How Enterprise RAG covers it

How deep it goes
Works through Dockerfile layers, build context, secret exclusion, registry publication, and tests run in the production image.
Examples
Uses a Python 3.11 RAG application with libgomp1, port 8000, app.py, Azure Container Registry, and pytest in GitHub Actions.
What it assumes
Teaches Dockerfile construction from project files while assuming an existing Python application, dependency list, and deployable service configuration.
What you can do after
Operate/configure it by building, running, tagging, publishing, and testing a deployable Docker image with externalized secrets.
How it connects
Connects Dockerfiles, .dockerignore, environment variables, container registries, Azure App Service, GitHub Actions, Kubernetes, and Cosmos DB.

Also explained in

Compare how 32 books explain container image →

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.