BuildBot

Containers from Scratch

Images vs. containers

Lesson 1 of 5

What you'll learn

  • Distinguish an image from a container
  • Understand that many containers run from one image
  • See why a container's writable layer makes it disposable

An image is a read-only blueprint, built from stacked layers. A container is a running instance of that image — it adds a thin writable layer on top where its changes live.

docker run --name web nginx:alpine
docker run --name web2 nginx:alpine

Both containers share the exact same read-only image layers. Nothing is copied. They differ only in their own writable layer and their identity (name, ID).

One image, many containers

The image is the durable artifact you build once and ship. Containers are cheap instances you create and destroy freely.

docker ps          # running containers (instances)
docker images      # images (blueprints)

Because every container's changes live only in its writable layer, deleting the container deletes those changes — the image is untouched.

Cattle, not pets

Treat containers as disposable. If one misbehaves, throw it away and start a fresh instance from the same image. Anything you need to keep belongs in a volume (covered later), not the writable layer.

Many containers, one image

Run it. Each container is a separate instance with its own ID and writable layer, but they all share one image.

Loading editor…

Next: how images are built layer by layer — and why the build cache makes order matter.

Sign in to save your progress across devices.