Docker packages an app together with everything it needs to run, so it behaves the same on your laptop, a colleague's laptop and a production server. It is the standard answer to 'it works on my machine'.
Why an app works on one machine and not another
An app depends on far more than its own code. It needs a particular version of its language runtime, the libraries it imports, system packages underneath those, environment variables, config files and an operating system that provides all of it. Together, that is the app's environment.
Two machines rarely have the same environment. You built the app with Python 3.12 and version 2 of a library; your colleague has Python 3.10 and version 1, installed a year ago for another project. The code is identical, but it runs on different ground, so it fails in ways that are hard to reproduce. Conflicts between packages make it worse, a problem covered in dependency hell.
The old fix was a README of setup steps. Those steps drift out of date, get skipped, and never quite match the server. Docker replaces the instructions with the environment itself.
Images and containers
Docker has two core ideas, and most confusion comes from mixing them up.
- An image is a read-only package: a filesystem holding the operating system files the app needs, its runtime, its dependencies and its code, plus metadata such as which command starts it. You build an image once.
- A container is a running instance of an image. It is an isolated process that sees its own filesystem, network and process list. You can start many containers from one image, the way you create many objects from one class.
Images are shared through a registry, such as Docker Hub or GitHub Container Registry. You push an image to it, and anyone with access can the exact same image and run it.
Wondering how this was made? How we make these