QA
Beginner LevelDocker & Deployment

What is the difference between a Docker Image and a Docker Container?

❓ Interview Prompt: Explain the relationship between immutable Docker images, read-only layer stacks, and running container instances.

Docker Image (Blueprint — Immutable):

A Docker Image is a read-only, layered filesystem snapshot containing application code, runtime, libraries, and environment configuration. Images are built once and can be shared via registries.

•
Each instruction in a Dockerfile creates a new read-only layer stacked on previous layers.
•
Images are content-addressable — identified by a SHA-256 digest.
•
Images are never modified once built. To change behavior, you build a new image.

Docker Container (Running Instance):

A Docker Container is a running process spawned from an image. Docker adds a thin writable layer on top of the image's read-only layers using Copy-on-Write (CoW).

•
Multiple containers can run from the same image simultaneously without conflicts.
•
When a container is stopped and removed, its writable layer is discarded (unless persisted via a Volume).
•
A container is to an image what a process is to an executable binary.

Lifecycle:

Image → docker run → Container (running) → docker stop → Container (stopped) → docker rm → Gone

Code Implementation Example

bash
# Pull an image (read-only blueprint)
docker pull node:20-alpine

# Inspect image layers
docker image inspect node:20-alpine --format '{{len .RootFS.Layers}} layers'
# Output: 8 layers

# Run 3 containers from the SAME image simultaneously
docker run -d --name app1 node:20-alpine sleep 3600
docker run -d --name app2 node:20-alpine sleep 3600
docker run -d --name app3 node:20-alpine sleep 3600

# All 3 share the same read-only image layers — each has its own tiny writable layer
docker ps   # shows 3 running containers
💡One image spawning three independent containers, each with its own isolated writable layer.
🎯 Interview Key Takeaway

Images are immutable read-only blueprints; containers are live running instances with a thin writable CoW layer on top.

#Docker#Images#Containers#Layers#Beginner
Back to all Docker & Deployment Questions→

More Docker & Deployment Interview Questions

Beginner LevelDocker & Deployment

How do Docker Multi-Stage Builds minimize image size and improve security?

Beginner LevelDocker & Deployment

What is the difference between a Docker Container and a Virtual Machine (VM)?

Beginner LevelDocker & Deployment

What are core Dockerfile instructions (FROM, WORKDIR, COPY, RUN, CMD, ENTRYPOINT)?