Images vs. containers

The analogy: a class, and its instances

An image is a fixed, built definition — a filesystem snapshot plus instructions for what to run — the same way a class is a fixed definition of attributes and behavior, not a specific object yet. A container is a running instance of that image — the same way Agent("research_agent", "claude-sonnet") produces one specific object from the Agent class. Exactly like a class, one image can produce many containers, each one an independent running instance, the same way agent_a and agent_b were separate instances of the same Agent class with their own separate state.

class Agent:
    def __init__(self, name: str):
        self.name = name

agent_a = Agent("research_agent")
agent_b = Agent("support_agent")

(the exact analogy, shown as Python — not part of this lesson’s code, just the comparison point)

docker build -t my-app .         # defines the "class" — the image
docker run --name run_a my-app   # one "instance" — a container
docker run --name run_b my-app   # a second, independent "instance"

(the Docker equivalent of the same shape)

Proving the isolation, live

Three panes, all started from containers of the same image (a small app with a counter.txt file inside it, starting at 0). Run pane A first — it increments its own copy of counter.txt. Then run panes B and C and compare:

Pane A — increments its own container's counter.txt
click Run to see this pane's output
Pane B — a separate container, same image
click Run to see this pane's output
Pane C — a brand-new container, started after Pane A's change
click Run to see this pane's output

Pane A’s change never touched pane B’s container, or the image itself — pane B still shows the original starting value. Pane C, a brand-new container started after pane A’s change, confirms the same thing from a different angle: it also starts fresh at 0, proving the change lived only inside that one specific container instance, not the image it came from.

This is the direct payoff of the analogy: modifying one Agent instance’s self.name never touches another instance, or the Agent class itself — modifying one running container never touches another container, or the image it was built from.

Check your understanding
1/3

What's the relationship between a Docker image and a Docker container, using the class/instance analogy?