Images and registries for Kubernetes
The container knowledge Kubernetes assumes: building a small, non-root image, tagging it properly, and pushing it to a registry the cluster can pull from, with a real push to Amazon ECR.
By the end of this lesson you'll be able to
0 of 4 completeVerified lab: the shop-web image built with Docker and pushed to a real Amazon ECR repository in
ap-south-1. The output shown is real.
Code walkthrough: none.
Cloud lab: ECR needs an AWS account (storage is a few cents per GB-month).
Kubernetes runs containers; it doesn't build them. Before a cluster can run your app, the app has to be an image in a registry the nodes can reach. The Docker course covers images in depth. This lesson is the short version Kubernetes needs, and it builds the shop-web app that every later lesson deploys.
An image built for Kubernetes
shop-web is a tiny Python web server. It answers / with a page, /api with JSON saying which
version and which Pod answered, /healthz for health checks, and /burn to use CPU in the
autoscaling lesson. The Dockerfile:
FROM python:3.13-alpine WORKDIR /app COPY app.py . RUN adduser -D -u 10001 app USER 10001 EXPOSE 8080 ARG APP_VERSION=v1 ENV APP_VERSION=$APP_VERSION CMD ["python", "app.py"]
Four choices here matter later:
- A small base image (
python:3.13-alpine). Smaller images pull faster when a Pod lands on a new node, which matters when autoscaling adds nodes under load. - A non-root user (
USER 10001). The Security lesson enforces the restricted Pod Security standard; images that need root fail it. - A fixed port (
EXPOSE 8080). The Service and health checks in later lessons point at 8080. - The version comes from the build (
ARG APP_VERSION), so/apireports which version a Pod runs. That makes rollouts and rollbacks visible.
The lab built three images: v1, v2, and v3-broken, which exits on start with
config error: DATABASE_URL is not set. You'll use v3-broken to see a failed rollout, a
CrashLoopBackOff and a Helm rollback.
Tags, not latest
Every Kubernetes manifest in this course names an exact tag: shop-web:v1. With :latest, two nodes
that pulled at different times can run different code under the same name, and "roll back to the
previous version" has no meaning. Tag every build with a version or the Git commit SHA, and never
reuse a tag.
Push it to a registry
A registry stores images; nodes pull from it. Docker Hub is public by default. For your own apps, use a private registry next to your cluster: Amazon ECR on AWS.
The lab created one:
$ aws ecr create-repository --repository-name shop-web --image-scanning-configuration scanOnPush=true { "name": "shop-web", "uri": "626159997645.dkr.ecr.ap-south-1.amazonaws.com/shop-web", "scanOnPush": true }
aws ecr create-repository --repository-name shop-web --image-scanning-configuration scanOnPush=trueawsthe AWS command line
scanOnPush makes ECR scan every pushed image for known vulnerabilities. The URI has three parts: the
account ID, the region, and the repository name. That full URI, plus a tag, is what goes in your Pod
specs.
Log Docker in to ECR (the password is a short-lived token), tag, and push:
$ aws ecr get-login-password --region ap-south-1 | docker login --username AWS --password-stdin 626159997645.dkr.ecr.ap-south-1.amazonaws.com Login Succeeded $ docker push 626159997645.dkr.ecr.ap-south-1.amazonaws.com/shop-web:v1 $ docker push 626159997645.dkr.ecr.ap-south-1.amazonaws.com/shop-web:v2 $ docker push 626159997645.dkr.ecr.ap-south-1.amazonaws.com/shop-web:v3-broken $ aws ecr describe-images --repository-name shop-web --------------------------------------------------------------- | DescribeImages | +-----------------------------------+-----------+-------------+ | pushed | sizeMB | tag | +-----------------------------------+-----------+-------------+ | 2026-11-09T05:40:15.891000+00:00 | 16943891 | None | | 2026-11-09T05:40:15.900000+00:00 | 1166 | None | ... | 2026-11-09T05:40:20.282000+00:00 | 16944155 | v3-broken | | 2026-11-09T05:40:18.329000+00:00 | 16943891 | v2 | | 2026-11-09T05:40:16.233000+00:00 | 16943891 | v1 | +-----------------------------------+-----------+-------------+
aws ecr get-login-password --region ap-south-1 | docker login --username AWS --password-stdin 626159997645.dkr.ecr.ap-south-1.amazonaws.comawsthe AWS command line--regionwhich Region|pipe: send output to the next commanddockerbuild and run containersloginsign in to a registry
docker push 626159997645.dkr.ecr.ap-south-1.amazonaws.com/shop-web:v1pushupload an image to a registry626159997645.dkr.ecr.ap-south-1.amazonaws.com/shop-web:v1the image
docker push 626159997645.dkr.ecr.ap-south-1.amazonaws.com/shop-web:v2626159997645.dkr.ecr.ap-south-1.amazonaws.com/shop-web:v2the image
docker push 626159997645.dkr.ecr.ap-south-1.amazonaws.com/shop-web:v3-broken626159997645.dkr.ecr.ap-south-1.amazonaws.com/shop-web:v3-brokenthe image
(The sizeMB column is really bytes: about 17 MB compressed, against 70 MB locally.) The untagged
entries surprise people: Docker's build tooling attaches attestations (provenance records of how
the image was built) and a multi-platform index, which the registry stores as separate manifests.
They're expected, not junk.
How nodes get permission to pull
ECR repositories are private. On EKS, the worker node group's IAM role carries the
AmazonEC2ContainerRegistryReadOnly policy, so the kubelet on each node can pull from ECR in the same
account with no password stored anywhere. For other private registries (GitHub Container Registry, a
Docker Hub private repo), you create a Secret of type kubernetes.io/dockerconfigjson and reference it
in the Pod spec as imagePullSecrets.
When a pull fails, the Pod shows ErrImagePull, then ImagePullBackOff. The Monitoring lesson reproduces it with a tag that doesn't exist.
Publish an image your cluster can pull
Build shop-web as v1 and v2 (different APP_VERSION build args), create a private repository with scan on push, push both tags, and list them. Record the repository URI and both image digests.
~/registry.txtReveal one safe solution
$ docker build -t shop-web:v1 --build-arg APP_VERSION=v1 . $ docker build -t shop-web:v2 --build-arg APP_VERSION=v2 . $ aws ecr create-repository --repository-name shop-web --image-scanning-configuration scanOnPush=true $ REG=<account>.dkr.ecr.<region>.amazonaws.com $ aws ecr get-login-password | docker login --username AWS --password-stdin $REG $ for t in v1 v2; do docker tag shop-web:$t $REG/shop-web:$t && docker push $REG/shop-web:$t; done $ aws ecr describe-images --repository-name shop-web --query 'imageDetails[].[imageTags[0],imageDigest]' --output text > ~/registry.txt
docker build -t shop-web:v1 --build-arg APP_VERSION=v1 .dockerbuild and run containersbuildbuild an image from a Dockerfile-t shop-web:v1name and tag the image--build-arg APP_VERSION=v1a build argument (visible in history).the build context: the files COPY can see
docker build -t shop-web:v2 --build-arg APP_VERSION=v2 .-t shop-web:v2name and tag the image--build-arg APP_VERSION=v2a build argument (visible in history)
aws ecr create-repository --repository-name shop-web --image-scanning-configuration scanOnPush=trueawsthe AWS command line
aws ecr get-login-password | docker login --username AWS --password-stdin $REG|pipe: send output to the next commandloginsign in to a registry
for t in v1 v2; do docker tag shop-web:$t $REG/shop-web:$t && docker push $REG/shop-web:$t; doneforloop over a listdostart of what the loop runs each timetaggive an image another nameshop-web:$tthe image, then its new name$REG/shop-web:$tthe image, then its new name&&run the next command only if this one workedpushupload an image to a registry$REG/shop-web:$t;the imagedoneend of the loop
aws ecr describe-images --repository-name shop-web --query 'imageDetails[].[imageTags[0],imageDigest]' --output text > ~/registry.txt--querypick fields from the JSON response--outputoutput format>write output to a file, replacing it
You should see v1 and v2 with digests (and possibly untagged attestation entries). No AWS account? Push to Docker Hub or GitHub Container Registry instead; the Kubernetes side is the same, with an imagePullSecret.
Try it yourself
0 of 5 steps doneRun each task in your own account or terminal, then tick it off.
Quick check
Why should Kubernetes manifests use image tags like v2 instead of latest?
Official reading for this lesson
Or get every quiz answer right and it completes itself.
Something unclear, wrong or out of date in this lesson? Tell me, and I'll fix it.