liveBook · Manning

Container image

As explained in Kubernetes in Action, Second Edition

A container image is an immutable package containing a container's filesystem, application, and runtime dependencies from which containers can be created.

A container image is an immutable package used to create containers. Think of it as a bundle containing an application, the filesystem and dependencies it needs, and metadata such as the executable to run. A container is the running process created from that image, not the image itself. section 2.1.2

Run an existing image

After installing Docker, run `docker run busybox echo "Hello World"`. If the image is not already local, Docker pulls it from a registry, creates a container, and prints `Hello World`. You do not need to install BusyBox separately. section 2.1.3

An image registry stores images for sharing. You can build an image locally, push it to a registry, and pull it on another computer. Containers created from it get a filesystem derived from the image; additional filesystems can also be mounted into them. section 2.1.2

Listing 2.1 A minimal Dockerfile for building a container image
FROM node:23-alpine      #1
COPY app.js /app.js       #2
COPY html/ /html      #3
ENTRYPOINT ["node", "app.js"]      #4

This minimal Dockerfile starts from `node:23-alpine`, copies in the application files, and sets the command to run when a container starts. section 2.2.2

Build an application image

From the directory containing the Dockerfile and application files, run `docker build -t kiada:latest .`. Docker builds the image and gives it the name `kiada` with the tag `latest`. Run `docker images` to see the resulting local image. section 2.2.2

Images consist of layers that multiple images can share, so a shared layer needs to be transmitted and stored only once. `docker history kiada:latest` shows the application’s build steps alongside those inherited from its base image. section 2.4 section 2.2.2

A Kubernetes Pod can name the image for its container in an `image` field, alongside settings such as the container port. The same application image built for local use can therefore be used when running the application with Kubernetes. section 5.2.1 section 2.2.2

Deleting a container does not delete its image: the stored image can be reused to create another container. To remove the image itself, use `docker rmi kiada:latest`; `docker image prune` removes unused images. section 2.2.5

How Kubernetes in Action, Second Edition covers it

How deep it goes
Works through running and building images, then identifies shared layers and image reuse without detailing the image file format.
Examples
Uses a BusyBox Hello World run, a Node.js application Dockerfile, and a Pod manifest naming an image.
What it assumes
Assumes Docker is installed for the commands but introduces images, registries, and containers before building an application image.
What you can do after
Build it from scratch with a Dockerfile and `docker build`, then run or select the image for a container.
How it connects
Connects container images to containers, image registries, Dockerfiles, image layers, and Kubernetes Pods.

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 Kubernetes in Action, Second Edition. The section links point to the parts of the book it draws on.