Understanding Images

A Docker image is a read-only template that contains everything needed to run an application; containers are running instances of images.

An image is a read-only package that contains your application code, a runtime, libraries and settings. A container is a running instance created from an image.

The image and container relationship

Think of an image like a class and a container like an object created from it. From one image you can start many containers.

An image is a template that produces multiple running containersImageread-onlyContainer 1Container 2Container 3docker run
One image can be used to launch many independent containers.

Where images come from

  • Pull a ready-made image from a registry like Docker Hub.
  • Build your own from a Dockerfile.

Example

Example · bash
# Pull an image, then list local images
docker pull python:3.12-slim
docker images

# Start two containers from the same image
docker run -d --name py1 python:3.12-slim sleep 1000
docker run -d --name py2 python:3.12-slim sleep 1000

When to use it

  • A developer pulls an official Node.js image from Docker Hub instead of setting up Node manually on every machine.
  • A team stores their application image in a private registry so every deploy pulls a deterministic, versioned artifact.
  • A QA engineer inspects image layers to understand exactly which files were added and when, for security auditing.

More examples

Pull an image from Docker Hub

Downloads the Node.js 20 Alpine image and lists all locally cached images.

Example · bash
docker pull node:20-alpine
docker images

Inspect image metadata

Shows full metadata and the layer history of the image, including each build instruction.

Example · bash
docker inspect node:20-alpine
docker image history node:20-alpine

Remove an unused image

Demonstrates how to free disk space by removing images that are no longer needed.

Example · bash
# Remove a specific image
docker rmi node:20-alpine

# Remove all dangling (unnamed) images
docker image prune

Discussion

  • Be the first to comment on this lesson.