What Docker is: the "works on my machine" problem
Containers versus virtual machines, images and containers, installing
A familiar situation: a program works on your computer but not on the server. The reason: a different Python version, a different library, a different setting. Docker solves this: it packs the program into a "box" together with everything it needs to run. Wherever the box is opened, it works the same. Docker appeared in 2013 and has become one of the standard ways to run programs on servers.
Containers versus virtual machines
| Virtual machine | Container | |
|---|---|---|
| Inside | a whole operating system | just the program and its libraries |
| Size | gigabytes | often tens to hundreds of MB |
| Start-up | minutes | seconds |
| Kernel | its own | shared with the host |
Containers are lightweight: one server easily runs dozens of them.
Two core ideas
| Idea | Analogy | Meaning |
|---|---|---|
| Image | a recipe / mould | an unchanging "snapshot" of the program and environment |
| Container | the cooked dish | a live instance started from an image |
You can start as many containers from one image as you like. Ready-made images live on Docker Hub: python, nginx,
postgres and thousands more.
Installing
- Windows / macOS: Docker Desktop (on Windows it works with WSL 2).
- Linux (Ubuntu): the
docker-cepackage, following the official docs.
Check:
$ docker --version
$ docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
💡 When several projects on one server (say, a site and a few Telegram bots) run in separate containers, they don't get in each other's way: each has its own Python version and libraries.