Why you need it
An app does not run on its own. It needs the right language version, libraries and system files on the machine. Ana's laptop has them. The server may not, so the same app that works for her fails there.
Think of it like this
A camper van. It carries its own bed, stove and water. Park it in any field and you can live in it, because you do not depend on what the field has.
Where you’ll find it
- Docker: Made containers easy to build and run on any laptop or server.
- Kubernetes: Runs containers across many servers for companies of every size.
- Cloud services: AWS Fargate and Google Cloud Run take your container and run it, with no server for you to set up.
What to know first
Artifact. One build, sealed and named, that is tested and then shipped as it is. See Build once, deploy many.
Dependency. Something the app needs to run but did not write itself, like python 3.12 or a library.
Operating system. The base software of a machine, like Linux. Its core part, the kernel, runs every program on that machine.
How it works
- The app needs more than its code. Ana's app needs
python 3.12. Her laptop has it. The server haspython 3.8, so the app fails there. This is the red strip in the animation. - Pack what it needs. Put python 3.12 and the libraries inside the box, next to the code. Now the box does not care what the server has. This is the blue tile hopping into the box.
- Image and container. The sealed box is an image: the app plus everything it needs, stored as files. A container is that image running. One image can run as many containers.
- Lighter than a whole machine. A container is not a whole computer. All containers on a server share that server's kernel, and each one only sees its own files. So it starts in about a second, where a full virtual machine takes about a minute.
- Runs anywhere. Any server that can run containers can run this one: python 2.7, no python at all, it does not matter. This is the "try another server" button in the animation.
An example
The app needs python 3.12 and 40 libraries. The server has python 3.8 and none of them.
Ana builds an image of about 150 MB with python 3.12, the 40 libraries and the code inside.
The server downloads it once and starts it in about 1 second. It runs, and so does the same image on 20 other servers.
Further reading
- What is a container?, Docker docs. A short, plain start, with a video and a try-it-yourself step. Start with this one.
- Dependencies, The Twelve-Factor App. Why an app should never rely on what happens to be on the machine.
- Images, Kubernetes docs. How images are named, fetched and kept the same everywhere.