liveBook · Manning

Image tag

As explained in Road to Kubernetes

A container image tag is a human-readable identifier attached to an image reference to distinguish a version, environment, or release.

Need a particular Python version in a container? Choose a tag from the image’s Docker Hub Tags tab. An image reference puts the tag after a colon: `python:3.11.4` selects the Python image with that version tag. The same pattern works for Node.js, such as `node:18.17.0`. section 5.3.1 section 5.4

Use a tagged image

Run `docker pull python:3.11.4` to download the image, or `docker run -it python:3.11.4` to open its Python shell. Put the same image reference in a Dockerfile’s `FROM` line when building an application image. section 5.3.1

Tags also label images you build. A single `docker build` can assign both a numbered tag, such as `:0.0.1`, and `:latest`; you can then push either the specific tag or all tags to Docker Hub. Docker uses `latest` when you omit a tag. A specific tag helps you identify the version you intend to deploy, but changing a tag does not itself change a container. section 5.5.1 section 7.2

Carry that label through the deployment process:

  • For different environments, build with tags such as `my-container:dev`, `my-container:stage`, and `my-container:prod`. Use the appropriate Dockerfile or other configuration to make the actual environment changes. section 7.2.1 section 7.2
  • In GitHub Actions, tag a build with both `latest` and `${{ github.sha }}` so it has a default label and a commit-specific label. section 6.1.2
  • In a Kubernetes Deployment, prefer an explicit version or commit ID for production auditing, debugging, and rollback. Reapplying an unchanged manifest that still says `:latest` does not tell Kubernetes to roll out an updated image; a rollout restart can force one. section 8.5.2
Listing 7.5 Tagging Docker Compose images
...
  web:
    image: codingforentrepreneurs/rk8s-py:${TAG:-latest}
    build:
      context: .
      dockerfile: Dockerfile
      tags:
        - "codingforentrepreneurs/rk8s-py:${TAG:-latest}"
...

The Compose example uses `${TAG:-latest}` in both the service image and build tag. Set `TAG=v1.0.0` to build with that tag; leave it unset to use `latest`. section 7.2.2

How Road to Kubernetes covers it

How deep it goes
Works through selecting, building, and deploying tags, but defers implementation of explicit production Deployment tags.
Examples
Uses Python and Node.js version tags, dual-tagged Docker builds, and a Compose configuration with a configurable tag.
What it assumes
Introduces tag selection through Docker Hub and docker pull before applying tags in Dockerfiles.
What you can do after
Operate/configure image selection and labeling across Docker builds, Compose environments, and Kubernetes Deployments.
How it connects
Connects image tags to Dockerfiles, Docker Hub, Docker Compose, GitHub Actions, and Kubernetes Deployments.

Also explained in

Compare how 6 books explain image tag →

Related concepts

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