Why Docker?
The "works on my machine" problem, solved.
You build an app on your laptop. It works perfectly. You send it to a teammate, or to a server, and it breaks: a different Python version, a missing library, another operating system. This is the oldest problem in software, and Docker exists to solve it.
- The problem: apps depend on their whole environment
- The idea: ship the app together with its environment
- The tool: containers, built and run with Docker
What is a container?
A container is a small, isolated box that holds your app and everything it needs to run: the code, the runtime, the libraries and the settings. The box runs the same way on any computer that has Docker, whether that is your laptop, a colleague's machine, or a cloud server.
Containers vs virtual machines
Virtual machines also isolate apps, but each one carries a full operating system, so they are big and slow to start. Containers share the host's kernel and only package what the app needs.
Virtual machine
- full guest operating system
- gigabytes in size
- boots in minutes
- heavy on memory
Container
- shares the host kernel
- megabytes in size
- starts in seconds
- run dozens on a laptop
The Docker vocabulary
| Word | Meaning | Analogy |
|---|---|---|
| Image | a read-only template with your app and its environment | a recipe |
| Container | a running instance of an image | a cake baked from the recipe |
| Dockerfile | a text file with the steps to build an image | the written recipe card |
| Registry | a place to store and share images (Docker Hub) | a recipe library |
Check your understanding
Summary
- Docker packages an app with its whole environment
- Containers are small, fast and portable
- Images are templates, containers are running copies