Advertisement
Beginner .NET, Docker & Containerization

What is the difference between an image and a container in Docker terminology, applied to a .NET application?

Short answer

An image is an immutable, built artifact (the result of a `docker build`) containing the application, its dependencies, and everything needed to run it, analogous to a class definition.

Save .NET mock interview
Advertisement
AModel answer
An image is an immutable, built artifact (the result of a `docker build`) containing the application, its dependencies, and everything needed to run it, analogous to a class definition. A container is a running (or stopped) instance of an image, analogous to an object instantiated from that class -- you can run multiple independent containers from the same single image simultaneously, each with its own isolated filesystem and process space.
docker build -t myapp:1.0 .          # builds an image
docker run -d --name instance1 myapp:1.0  # runs a container from that image
docker run -d --name instance2 myapp:1.0  # runs ANOTHER independent container from the SAME image
Real-world example
A load-tested API runs five separate containers from the same built image behind a load balancer, scaling horizontally by simply starting more container instances rather than building anything new for each one.
Likely follow-ups
  • What happens to data written inside a container when it stops or is removed?
  • How do you persist data across container restarts using volumes?
Related topics