Introduction to Docker
The tool that ended 'but it works on my machine' forever.
Before Docker, moving an app from a developer’s laptop to a production server was painful — different OS versions, missing libraries, mismatched configs. Docker packages your app and everything it needs into a single, portable unit called a container that runs the same way everywhere.
🎯 Learning Objectives
By the end of this lesson you will:
- Understand what a container is
- Know how containers differ from virtual machines
- Understand the core Docker concepts: image, container, registry
- Run your first container
What is a Container?
A container is a lightweight, isolated environment that holds your application plus its dependencies (libraries, runtime, config). It shares the host’s operating system kernel but runs as if it had its own private machine.
💡 The lunchbox analogy
A container is like a sealed lunchbox: whatever you pack (your app + dependencies) travels together and arrives exactly as you packed it — no matter whose fridge (server) you put it in.
Containers vs Virtual Machines
Both isolate workloads, but they work very differently:
| Container | Virtual Machine | |
|---|---|---|
| Contains | App + dependencies | A full guest OS + app |
| Size | Megabytes | Gigabytes |
| Startup | Seconds or less | Minutes |
| Isolation | Process-level (shares host kernel) | Full OS-level |
| Density | Hundreds per host | A handful per host |
VM: [App][Guest OS] [App][Guest OS] ← heavy
\_____ Hypervisor _____/
Container: [App][App][App][App] ← light
\_____ Docker Engine ___/
\_______ Host OS _______/Containers are lighter and faster because they skip the extra guest operating system.
The Three Core Concepts
| Concept | What it is |
|---|---|
| Image | A read-only template/blueprint (your app packaged up) |
| Container | A running instance of an image |
| Registry | A store for images (e.g. Docker Hub) |
The relationship, in one line: you pull an image from a registry and run it to create a container.
Registry ──pull──▶ Image ──run──▶ ContainerRun Your First Container
Docker Hub has a tiny test image called hello-world:
docker --version # check Docker is installed
docker run hello-world # pull + run a test containerDocker couldn’t find the image locally, so it pulled it from the registry, then ran it as a container. That’s the whole loop.
🧪 Hands-on Lab
Run and Inspect a Real Container
- Run an Nginx web server container in the background on port 8080
- List the running containers
- Confirm it responds, then stop it
🧠 Knowledge Check
What is the main difference between a container and a virtual machine?
What is the relationship between an image and a container?
💼 Interview Preparation
Why did Docker become so important for DevOps?
Summary
You now understand containers, how they differ from VMs, and the image → container → registry model. Next, you’ll work hands-on with images and containers and learn the everyday Docker commands.