What is the difference between a Docker image and a container?
BeginnerConceptContainers & Kubernetes basics
Answer
In one line: An image is a read-only template containing the app and everything it needs; a container is a running instance of that image — like a class and an object, or a recipe and the dish.
Docker image
- Built from a
Dockerfilewithdocker build. - Made of layers — each instruction (
FROM,RUN,COPY) adds a read-only layer. Layers are cached and shared between images, which saves space and speeds up builds. - Stored in a registry (Docker Hub, ECR, ACR) and identified by a name, tag and digest:
orders:1.4.2,orders@sha256:9f.... - Never changes once built (immutable).
Container
- Created from an image with
docker run(or by Kubernetes). - Adds a thin writable layer on top of the image layers; any files written there are lost when the container is removed (unless you use volumes).
- Has its own process space, network and filesystem view, isolated using Linux namespaces and limited using cgroups.
- You can run many containers from the same image.
Commands that show the difference:
docker build -t orders:1.4.2 . # creates an IMAGE
docker images # lists images
docker run -d --name o1 orders:1.4.2 # starts a CONTAINER from the image
docker run -d --name o2 orders:1.4.2 # a second container, same image
docker ps # lists running containers
Why it matters in DevOps:
- The image is the artifact you build once and promote through environments.
- Containers are disposable: if one fails, start a new one from the same image.
- Data that must survive goes into volumes or external storage, not the container's writable layer.
Tip for interviews: mention layers and the writable container layer — it shows you know how images and containers work under the hood.
More on Containers & Kubernetes basics
What makes a good Dockerfile? Give some best practices.BeginnerWhat is Kubernetes, and why do we need it?BeginnerExplain the Kubernetes architecture in simple terms.BeginnerWhat are Pods, Deployments and Services in Kubernetes?BeginnerWhat are liveness, readiness and startup probes?BeginnerWhat are resource requests and limits in Kubernetes?Beginner