Interview Prep/DevOps Fundamentals/Containers & Kubernetes basics

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 Dockerfile with docker 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.

All DevOps Fundamentals questions

More on Containers & Kubernetes basics