← again tap: answer good → ↑ swipe up at the end: next
Question
What is a Docker image, and how does it relate to a container?
Answer
An image is a read-only, layered template (filesystem plus metadata); a container is a running instance of it with its own thin writable layer on top.
An image bundles everything an application needs to run: a minimal OS filesystem (for example Alpine), libraries, the application files, and metadata such as environment variables, the exposed port and the default command. It is built from a Dockerfile and stored as a stack of layers, one per filesystem-changing instruction, each layer recording only the difference to the one below.
Images are immutable. When you start a container, Docker stacks the image's read-only layers and adds one thin writable layer for that container. Everything the running process changes goes into that writable layer, so:
- many containers can start from the same image and share its layers on disk, which is why ten containers do not cost ten times the space;
- deleting the container throws away its writable layer, while the image stays unchanged.
The class/object analogy fits: the image is the class, each container an instance.
Because several container engines exist besides Docker (Podman, containerd, CRI-O), the Open Container Initiative (OCI) standardises the image format (how layers and their metadata look), so an image built with one tool runs on another.
* Shared read-only layers below, one private writable layer per container on top. *
Go deeper:
Fireship: Docker in 100 Seconds — images, containers and Dockerfiles in a fast two-minute overview.
Docker Docs: What is an image? — layers, immutability and how images are composed.
Wikipedia: Docker (software) — history, architecture and the components around the engine.
Question
Where do Docker images come from, and how does a short name like alpine:latest resolve to a registry?
Answer
From a registry, by default Docker Hub: alpine:latest is short for docker.io/library/alpine:latest.
A registry is a server that stores and distributes images, organised into repositories with tags (versions). Docker Hub (hub.docker.com) is the default public registry; others include GitHub Container Registry (ghcr.io), Quay and private, self-hosted registries.
An image reference has the form [registry/][namespace/]repository[:tag]. Whatever is left out gets a default:
| Part | Default | In alpine:latest |
|---|---|---|
| Registry | docker.io (Docker Hub) |
docker.io |
| Namespace | library (the curated "official images") |
library |
| Tag | latest |
latest (given) |
So when docker image build meets FROM alpine:latest and the image is not cached locally, the build output shows it being pulled from docker.io/library/alpine:latest. A name like myregistry.example.com:5000/team/app:1.2 points somewhere else entirely.
latest is just a tag name, not a guarantee of anything. It is whatever the publisher last tagged that way, so pin a concrete tag (or a digest) when reproducibility matters.
Go deeper:
Docker Docs: What is a registry? — registries, repositories and tags, with a hands-on push and pull.
Docker Docs: Docker Official Images — what the curated
librarynamespace is and why it is trusted.