Docker for Kubernetes · Reference
Glossary
Lessons use these words in exactly these senses. The "In Kubernetes" notes point forward to the Kubernetes Topic.
Images
- Image
- A read-only package of the files, libraries and default settings an app needs, built as a stack of layers. It never changes after it is built; a change means a new image. In Kubernetes: a Pod's container names the image to run.
- Layer
- One set of file changes (added, changed, deleted) in an image. Layers are shared between images and containers that use them.
- Image reference
- The name you type,
repository:tag, such asalpine:3.20. With no tag, Docker assumes:latest, which is just a default tag name, not "the newest". - Registry
- A server that stores images so they can be pulled elsewhere, such as Docker Hub.
docker runpulls a missing image from it automatically.
Building
- Dockerfile
- A text file of instructions that
docker buildreads top to bottom to make an image. - Base image
- The image named in
FROMthat yours builds on, such aseclipse-temurin:21-jdk. Your layers go on top of its layers. - Build context
- The set of files a build can access: the last argument to
docker build, usually.. COPY paths are relative to it. - Build time / run time
- Build time is
docker build: FROM, WORKDIR, COPY and RUN take effect once, and the result is frozen into the image. Run time is everydocker run: CMD starts the main process, again for every container. - Build cache
- Docker's store of earlier build steps. A step whose inputs haven't changed is reused (
CACHED). A step that changed reruns, and so does every step after it in the same stage. - Stage (multi-stage build)
- The part of a Dockerfile from one
FROMto the next. Name it withFROM … AS build. Only the last stage becomes the image; earlier stages contribute only whatCOPY --fromtakes. - .dockerignore
- A file at the root of the build context listing paths to leave out of it, with the same idea as
.gitignore. Ignored files are never sent to the builder, and COPY can't see them. - JDK image / JRE image
- A JDK image (
eclipse-temurin:21-jdk) can compile and run Java. A JRE image (21-jre) can only run it. Build with a JDK and ship with a JRE. - Exec form / shell form
- Exec form,
CMD ["java", "App"], runs the program directly as PID 1. Shell form,CMD java App, wraps it in/bin/sh -c, so the shell is PID 1 and the program doesn't receive signals. Use exec form for CMD. - Expose / publish
EXPOSErecords in the image which port the app listens on. Publishing (docker run -p host:container) actually makes it reachable from your machine.
Containers
- Container
- An isolated process started from an image, plus its own thin writable layer. Many containers can share one image.
- Writable layer
- The container's private top layer, where every file it writes or deletes is recorded. It survives stop and start, and is deleted when the container is removed.
docker diffshows it. - Main process (PID 1)
- The command a container runs: the image's default, or the one you put after the image name. The container is running exactly while this process runs.
docker stopsends itSIGTERM, thenSIGKILLafter a grace period (10 seconds by default). - Exit code
- The number the main process ended with, shown as
Exited (N). 0 means success. Above 128 means it was ended by a signal: 143 = SIGTERM (stopped politely), 137 = SIGKILL (killed). - Running / Exited
- The two states you'll see most. Exited containers still exist, with their writable layer, until removed.
docker psshows running containers only;docker ps -ashows all of them. In Kubernetes: a crashed container is restarted with a clean state, not resumed. - Immutable container
- The practice of never patching a running container: build a new image, then replace the container.
Runtimes and standards
- Docker Engine
- The daemon that builds images and runs containers on your machine. The
dockercommand is its client. - Container runtime
- The software that actually runs containers. Docker Engine uses containerd underneath. In Kubernetes: nodes talk to a runtime such as containerd or CRI-O through the CRI, not to Docker Engine.
- OCI
- Open Container Initiative: the standard formats for images and for running containers. They are why an image built with Docker runs on any Kubernetes node.