What is a Docker image and how is it different from a Docker container?

Beginner

Answer

A Docker image is a read-only template containing application code, runtime, libraries, and dependencies. A Docker container is a running instance of an image.
Key differences:

  • Images are immutable blueprints; containers are mutable runtime environments
  • Images are stored; containers are executed
  • Multiple containers can be created from a single image
  • Changes to containers don't affect the original image
    Example:
# Image exists as a template
docker images
# Container is created and runs from image
docker run nginx