Images vs. Containers

Difficulty: Beginner

Question

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

Answer

A **Docker Image** is a read-only template with instructions for creating a Docker container. It's like a class in OOP.

A **Docker Container** is a runnable instance of an image. You can create, start, stop, move, or delete a container using the Docker API or CLI. It's like an object (instance of a class) in OOP.

Code examples

Basic Commands

# Build an image
docker build -t my-app .

# Run a container from that image
docker run -d --name my-running-container my-app

The 'build' command creates the image (template), and the 'run' command creates a live instance (container) from that template.

Key points

Concepts covered

Image, Container, Layer, Storage