Skip to content

Lesson 24 of 24Kubernetes

Wrap-Up: Docker

Tie the whole course together: one real app taken from a laptop to a GitOps-managed cluster, a mixed review, and where to go next.

15 min read0/6 questions

You started this course with the question "what is a container, really?" and a single docker run. Since then you have written Dockerfiles, wired whole stacks together with Compose, made images small, fast and safe, proved where they came from, and run them on Kubernetes from a git repo. On the job these steps never come separately. This lesson lines them up once more, then walks one app through all of them.

The path you took

Docker, unit by unit
  1. Unit 1

    Containers

    Images, layers, Dockerfiles, the CLI, volumes and networks gave you one container you understand, ready to be combined with others.

  2. Unit 2

    Real apps

    Compose, multi-stage builds, production habits, resource limits and a debugging routine turned single containers into a stack you can run and fix.

  3. Unit 3

    Building images well

    The build cache, BuildKit and multi-arch builds made those images fast to build and able to run on any machine, so they were worth securing.

  4. Unit 4

    Security and supply chain

    Hardening, scanning, SBOMs, signing and registries made each image something you can trust and move safely between environments.

  5. Unit 5

    Kubernetes

    Workloads, networking, probes, config and GitOps ran those trusted images across a cluster, changed only through git.

  6. Now

    Wrap-up

    One app taken through all five units in the order you would really work.

How it fits together

The ticket: "Our shop app runs on one hand-built VM. Move it to containers and onto the platform team's Kubernetes cluster. New starters should have it running locally within an hour." The app has a React frontend, a FastAPI API, a background worker that resizes images, and Postgres. Here is how the course shows up, in the order you would really work.

First image. You start with the API, because everything else depends on it. Following Writing a Dockerfile, you copy pyproject.toml and the lock file first, install dependencies, and only then copy the source, so a code change does not reinstall every package. A .dockerignore keeps .venv and .git out of the build context. You run it with the flags from Docker CLI Essentials and check that the image and its running container are separate things, as Images and Containers showed.

The whole stack locally. One compose.yaml from Docker Compose brings up the API, the worker, the frontend and Postgres. The API reaches the database at db:5432, by service name, because Volumes and Networking taught you that localhost inside a container means that container. Postgres data lives in a named volume, so docker compose down does not wipe it. The API waits on a real healthcheck instead of a sleep. For daily work, Compose for Local Development adds watch mode and an override file, and keeps the container's .venv from being hidden by the bind mount. New starters run one command.

Production images. Dockerizing a Full-Stack App splits each Dockerfile into stages. The React build ends as static files served by Nginx, and the API image ships only the virtual environment, not the compilers. Docker in Production adds a slim base, a non-root user, no secrets baked in, and an exec-form CMD so the app gets SIGTERM and finishes its requests before the container stops.

The first incident. In staging, the worker restarts every few minutes. Using the triage order from Debugging Containers, you check the exit code first: 137. Resource Limits, Restarts and Logging Drivers explains it. The kernel OOM killer stopped the process at its memory limit, because the worker loads full-size images into memory. You stream the files instead and set the limit from measured usage.

Faster, wider builds. CI builds take nine minutes. Image Layers and the Build Cache helps you find the instruction that breaks the cache, and BuildKit, Cache Mounts and Advanced Multi-Stage Builds adds a cache mount for uv and a registry-backed cache, so CI reuses layers between runs. Half the team uses Apple Silicon and the cluster runs on arm64 nodes, so Multi-Architecture Images (amd64 and arm64) gives you one tag with both platforms behind an image index.

Trusting the image. Container Security in Depth drops all capabilities, sets a read-only root filesystem with a writable /tmp, and runs as a numeric UID. Scanning, SBOMs and Signed Images adds a scan that fails on fixable critical issues, an SBOM, provenance, and a keyless cosign signature. Registries and Image Distribution has CI push with short-lived OIDC credentials instead of a stored password, tag with the git SHA, and promote to production by digest.

Onto the cluster. From Containers to Kubernetes turns each app into a Deployment and a Service. Kubernetes Workloads and kubectl makes the database migration a Job and keeps the worker as its own Deployment. Services, Gateway API and Network Policies routes traffic in through a Gateway and adds default-deny policies, so only the API can reach Postgres. Config, Secrets, Probes and Autoscaling adds a readiness probe, a liveness probe that does not touch the database, requests and limits based on staging numbers, and an autoscaler on the API.

Shipping by git. Finally, Helm, Kustomize and GitOps Deploys gives you a Kustomize base with staging and production overlays in a config repo. CI bumps the image digest there, and Argo CD applies it. Rolling back is a git revert.

No unit worked alone. The non-root user made the read-only filesystem possible, the SHA tag made promotion by digest possible, and the healthcheck you wrote for Compose became the readiness probe on the cluster. That chain, from one Dockerfile to a git commit that changes production, is what container work looks like.

Check yourself

Quick check
A Dockerfile copies the whole project, then runs pip install -r requirements.txt. Every one-line code change reinstalls all dependencies. What is the fix?
Need a nudge? A hint rules out a wrong answer.
Quick check
In Compose, the API container fails to connect to Postgres at localhost:5432, even though the db service is running. Why?
Need a nudge? A hint rules out a wrong answer.
Predict the outputShell

The worker loads a 300 MB file fully into memory, and its container has a 128 MB memory limit. What exit code does echo $? print?

docker run --memory=128m shop-worker:1.4
echo $?
Need a nudge? Hints walk you through it.
Match the pairs0/6 matched

Match each need to the tool from this course that meets it.

Choose an item, then its match on the other side.
Put it in order6 steps

Put a change's journey from merged pull request to running pod in order.

  1. Tap the steps below in the right order.
Need a nudge? A hint shows where it starts.
Quick check
The API's liveness probe runs a database query. Postgres goes down for two minutes. What happens?
Need a nudge? A hint rules out a wrong answer.

What you can do now

  • Write a clean, cache-friendly, multi-stage Dockerfile for a Python or Node app.
  • Run a full stack locally with Compose, with persistent data, healthchecks and a fast edit loop.
  • Ship images that are small, non-root, free of secrets, and shut down cleanly.
  • Debug a container that crashes, hangs or cannot be reached, starting from its exit code and logs.
  • Build multi-arch images in CI with a remote cache, scan and sign them, and promote them by digest.
  • Read and write basic Kubernetes manifests, probes and overlays, and work on a team that deploys through GitOps.

That is a solid working level, enough to own the containers for a team's services. It is not yet running a cluster yourself: upgrades, node pools and cluster-wide security are platform engineering, and they come with time on the job.

Mistakes that still catch people

  • Using localhost between containers. It points at the container itself. Revisit Volumes and Networking.
  • Shell-form CMD, so SIGTERM never reaches the app. Shutdowns take the full timeout and drop requests. Revisit Docker in Production.
  • Baking secrets into an image. A later rm does not remove them from earlier layers. Revisit Docker in Production and Container Security in Depth.
  • Deploying a mutable tag like latest. Two nodes can run two different images. Revisit Registries and Image Distribution.
  • Treating exit 137 as a bug in your code. It is usually the memory limit. Revisit Resource Limits, Restarts and Logging Drivers and Debugging Containers.
  • Dependency checks in liveness probes. One database blip restarts everything. Revisit Config, Secrets, Probes and Autoscaling.

Where to go next

The natural next course is AWS. Your images need a home, and AWS gives you ECR for the registry, ECS on Fargate for simple container hosting, and EKS when you need Kubernetes, along with the IAM roles that make keyless CI pushes work. If you have not done it yet, System Design shows where containers sit in a larger architecture, with load balancers, queues and caches.

Real practice matters as much as the next course:

  • Containerise a project of your own end to end. Project: A Containerised Link Shortener gave you the pattern; now apply it to your own code. Compose for local work, a multi-stage production image, CI that scans, signs and pushes, and a deploy to a managed platform or a local kind cluster.
  • Contribute to an open-source project's container setup. Many projects have slow or root-running Dockerfiles. A focused PR that shrinks the image or adds a healthcheck is welcome and teaches you a lot.
  • Read the official docs. The Docker docs on building and Compose, the Kubernetes concepts pages, and the Argo CD or Flux getting-started guides.
Key terms
image
A read-only, layered package of a filesystem and metadata from which containers are started.
build cache
Stored layers that BuildKit reuses when an instruction and everything before it are unchanged.
multi-stage build
A Dockerfile with several stages, where the final image copies only what it needs from earlier ones.
digest
A content hash that names one exact image, unlike a tag, which can be moved.
OOM kill
The kernel stopping a process that exceeds its memory limit, seen as exit code 137 or OOMKilled.
readiness probe
A Kubernetes check that decides whether a pod should receive traffic, without restarting it.
GitOps
Deploying by changing a git repo that an in-cluster controller continuously applies to the cluster.