Container Image
A container image is a read-only, layered package of an application and its filesystem, plus metadata such as the default command. It is the template a runtime uses to create containers.
What is inside an image
An image is a stack of immutable layers plus a configuration (entrypoint, environment, exposed ports, user) and a manifest listing them. Layers are content-addressed, so identical layers are stored once and shared between images and containers on the same host. A running container adds one thin writable layer on top.
Build, inspect, and ship
docker build -t payment-api:v3.1.0 .docker history payment-api:v3.1.0 # layers and sizesdocker image inspect payment-api:v3.1.0 # config, env, layersdocker tag payment-api:v3.1.0 registry.example.com/payment-api:v3.1.0docker push registry.example.com/payment-api:v3.1.0docker image prune # remove dangling imagesNaming
[registry/][namespace/]name[:tag][@digest]nginx:1.27 -> docker.io/library/nginx:1.27123456789012.dkr.ecr.ap-south-1.amazonaws.com/payment-api:v3.1.0Common problems
| Problem | Cause | Fix |
|---|---|---|
pull access denied |
Not logged in or no permission | docker login |
manifest unknown |
Tag does not exist | Check exact tag |
| Image too large | Dev tools in final image | Multi-stage build |
| CVEs found | Old base image | Update base, rescan |
Common MistakeDeploying
:latest. It is a mutable tag, so production can silently run different code than you tested. Use a version or git SHA, or pin a digest.
Tip
docker history --no-truncshows which instruction created each layer, which finds your size problems quickly.
Frequently Asked Questions
What is the difference between an image and a container?
An image is the static, read-only template. A container is a running instance of it with a writable layer, its own process, and its own network. One image can back many containers at once.
Why are images built in layers?
Layers are cached and shared. If only your application code changes, Docker rebuilds and transfers just that layer, and many images can reuse the same base layers on disk and in registries.
Does deleting a file in a later layer shrink the image?
No. Earlier layers are immutable, so the deleted file stays in them. Clean up in the same RUN instruction that created the file, or use a multi-stage build.