Skip to main content

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.

flowchart TD I[Image: read-only layers] --> C1[Container 1 plus RW layer] I --> C2[Container 2 plus RW layer] I --> C3[Container 3 plus RW layer] classDef img fill:#EDE9FE,color:#1E293B classDef ctr fill:#D1FAE5,color:#1E293B class I img class C1,C2,C3 ctr

Build, inspect, and ship

Bash
docker build -t payment-api:v3.1.0 .
docker history payment-api:v3.1.0 # layers and sizes
docker image inspect payment-api:v3.1.0 # config, env, layers
docker tag payment-api:v3.1.0 registry.example.com/payment-api:v3.1.0
docker push registry.example.com/payment-api:v3.1.0
docker image prune # remove dangling images

Naming

Bash
[registry/][namespace/]name[:tag][@digest]
nginx:1.27 -> docker.io/library/nginx:1.27
123456789012.dkr.ecr.ap-south-1.amazonaws.com/payment-api:v3.1.0

Common 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 Mistake

Deploying :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-trunc shows 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.

Found a mistake, an outdated step or a broken link?