liveBook · Manning

Container image

As explained in Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform

A Docker image is an immutable package containing the code, dependencies, assets, and resources needed to instantiate a containerized application or service.

A container image is an immutable, bootable snapshot of a server or microservice. It packages the application code, dependencies, assets, and other resources needed to instantiate a container. section 3.4

Use an image as the deployable artifact in this workflow:

  • Create a Dockerfile describing the application, dependencies, base image, and supporting assets. section 3.8.1
  • Build the image with docker build, assigning a useful name and version tag. section 3.12 section 6.8.1
  • Run the image as a container to test the packaged microservice. section 3.6
  • Tag the image with the container registry address, log in, and push it for deployment. section 6.11.2
  • Point Kubernetes deployment configuration at the published image and verify the resulting pods, deployment, and service. section 7.12

Build and publish a versioned image

For a video-streaming microservice, build version 1, tag it for the target registry, authenticate, and push it: docker build -t video-streaming:1 --file Dockerfile-prod .; docker tag video-streaming:1 <registry-url>/video-streaming:1; docker login <registry-url>; docker push <registry-url>/video-streaming:1. Increment the version tag for later deployments. section 6.11.2

Listing 3.1 A Dockerfile for our video-streaming microservice
FROM node:18.17.1        #1
 
WORKDIR /usr/src/app     #2
COPY package*.json ./    #3
RUN npm ci --omit=dev    #4
COPY ./src ./src         #5
COPY ./videos ./videos   #6
 
CMD npm start            #7

Inspect a complete Dockerfile that derives from node:18.17.1, installs production dependencies, copies application assets, and defines the startup command. section 3.8.1

Immutability makes a built image a stable artifact: tests and security checks remain valid because the image cannot be modified. A running container may change its filesystem, but those changes do not alter the source image. section 3.4

How Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform covers it

How deep it goes
Defines image contents and immutability, then gives build, tagging, publishing, and deployment steps without exploring image internals.
Examples
Uses a Node.js video-streaming microservice, a Dockerfile, versioned command-line builds, registry pushes, and Kubernetes deployment configuration.
What it assumes
Assumes a microservice project and Docker installation, while introducing Dockerfiles, image commands, registries, and container deployment.
What you can do after
Build and publish a versioned microservice image, run it as a container, and deploy it through Kubernetes.
How it connects
Connects images to containers, Dockerfiles, container registries, Docker Hub, microservices, and Kubernetes clusters.

Also explained in

Compare how 25 books explain container image →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform. The section links point to the parts of the book it draws on.