Skip to main content

Docker Images

Recipes for the Lunchbox

Think of Docker images as recipes. A recipe tells you what ingredients to use and how to prepare them. Once you follow the recipe, you get a dish. In Docker, the recipe is the image, and the dish is the container. Every time you want to serve the same dish, you don’t rewrite the recipe - you just cook it again.

Docker images are the blueprints that define what goes inside a container: operating system, libraries, dependencies, and application code. Understanding images is crucial because they are the starting point for every container you’ll ever run.


Images Foundations

1. What is a Docker Image?

  • A Docker image is a read‑only template used to create containers.
  • It contains everything needed to run an application: code, runtime, libraries, environment variables, and configuration files.
  • Images are immutable - once built, they don’t change.

2. Image Layers

  • Images are built in layers, each representing a set of changes.
  • Example:
    • Base layer: Operating system (e.g., Alpine Linux).
    • Next layer: Installed packages (e.g., Python).
    • Next layer: Application code.
  • Layers are cached and reused, making builds faster and more efficient.

3. Union File System

  • Docker uses a Union File System to stack layers together.
  • Each layer is read‑only, but when combined, they form a complete filesystem for the container.
  • Containers add a thin writable layer on top of the image.

4. Image Lifecycle

  1. Pull: Download an image from a registry (e.g., Docker Hub).
  2. Build: Create a new image using a Dockerfile.
  3. Run: Start a container from the image.
  4. Tag: Assign a version or name to the image.
  5. Push: Upload the image to a registry for sharing.

5. Registries

  • Docker Hub: Default public registry with thousands of prebuilt images.
  • Private Registries: Enterprises use them for secure, internal images.
  • Other Registries: AWS ECR, Azure Container Registry, Google Artifact Registry.

Things to Remember

  • Images are blueprints; containers are instances of those blueprints.
  • Layers make images efficient and reusable.
  • Registries are the distribution hubs for images.

Hands‑On Lab

Step 1: Pull an Image

docker pull nginx
  • Downloads the nginx image from Docker Hub.

Step 2: List Images

docker images
  • Displays all images stored locally.

Step 3: Inspect an Image

docker inspect nginx
  • Shows detailed metadata about the image, including layers.

Step 4: Run a Container from the Image

docker run -d -p 8080:80 nginx
  • Starts an Nginx web server container.

Practice Exercise

  1. Pull three different images (ubuntu, alpine, redis).
  2. Use docker images to compare their sizes.
  3. Run containers from each image and observe differences in startup time and behavior.
  4. Inspect the alpine image to see why it’s so lightweight compared to ubuntu.

Visual Learning Model

Registry (Docker Hub)
       ↓
   Docker Image (layers)
       ↓
   Container (image + writable layer)

The Hackers Notebook

Docker images are the foundation of containers. They are built in layers, stored in registries, and used to create containers. By mastering images, learners gain control over how applications are packaged, shared, and deployed.


Tips, Tricks, Roadmaps, Resources, Networking, Motivation, Guidance, and Cool Stuff ♥

Updated on Dec 26, 2025