Module 3 Lesson 1: Images vs. Containers (The Builder's View)
Review the fundamental split between static blueprints and live processes, and learn how this distinction shapes the way we build and share software.
Module 3 Lesson 1: Images vs. Containers
We’ve touched on this before, but in this module, we are moving from Consuming (running other people’s images) to Producing (building our own). To do that, the difference between an Image and a Container must be crystal clear.
1. The Analogy Check-in
| Image (The Blueprint) | Container (The House) |
|---|---|
| Stored in a Registry (Docker Hub) | Runs on an Infrastructure (Cloud/Server) |
| Weighs Gigabytes of disk space | Weighs Megabytes of RAM (while running) |
| Is "Immutable" (Cannot be changed) | Is "Dynamic" (Can have internal state) |
| Shared via the internet | Deleted when no longer needed |
2. Why "Immutable" Images are Good
Imagine you have a bug in your app.
- Old Way: You log into the server, change 3 lines of code, and restart the service. Problem: Now your server is "Different" from your local machine. This is "Configuration Drift."
- Docker Way: You write a new Dockerfile, build a New Image, and replace the old container with a new one. Benefit: You are 100% sure that what you tested is exactly what is running.
Visualizing the Process
graph TD
Start[Input] --> Process[Processing]
Process --> Decision{Check}
Decision -->|Success| End[Complete]
Decision -->|Retry| Process
3. The Composition of an Image
An image is not just one file. It is a JSON Manifest that says:
- "Start with
Layer A(Ubuntu)." - "Apply
Layer B(install Python)." - "Apply
Layer C(copy my code)." - "When starting, run the command
python app.py."
When you "Pull" an image, Docker downloads these layers in parallel. If you already have Layer A from another image, Docker skips it. This is why Docker is so fast.
4. Turning an Image into a Container
When you run docker run my-app:
- Docker finds the image layers on your disk.
- It creates a Read-Write partition (the Writable Layer) for that specific container.
- It gives the container an IP address.
- It starts the process defined in the image manifest.
Exercise: The Blueprint Challenge
- If you have a "Running" container and you pull the power cord on your computer, what happens to the Image? What happens to the Container?
- Why do we say an Image is "Static" and a Container is "Dynamic"?
- Think of a physical "Standard" (like a LEGO brick or a USB port). How is a Docker Image similar to these standards?
Summary
Images are for Storage and Distribution. Containers are for Execution. In this module, we will learn how to write the "Instruction Manual" for an image: the Dockerfile.
Next Lesson: your first build: Dockerfile basics.