Docker Explained: What Is Actually Inside a Container?
What the video says
It works on my machine
Your app runs fine on your laptop. On the server, it breaks. The classic complaint: it works on my machine. So what is actually inside that container?
Apps on a server share its libraries. This app needs an old version, that app a new one, and they step on each other. Docker was shown at PyCon in March 2013. By June 2015, the Open Container Initiative launched, to set open standards.
A container is a process
Picture a shared kitchen hall. Each cook is a process. The gas, water and power under the floor are the kernel, and every cook shares it. A container is not a small computer. It is an ordinary process that the kernel fences in.
Namespaces: what it can see
The first fence is namespaces: what the process can see. Glass walls go up. The cook sees its own list of processes. Its own network. Its own files. Its own hostname.
Cgroups: how much it can use
The second fence is control groups, or cgroups: how much the process may use. A meter on the gas and water, for memory and CPU. But by default, a container has no limit at all, until you set one.
The image: shared layers
Now the files. An image is a stack of read-only layers, like crates on a trolley: base ingredients, tools, the recipe. Each container adds a thin writable layer on top, a tray for today's mess. 2 containers from the same image share the crates below. Delete a container, and its tray goes with it.
Why not a server or a VM?
Why not install every app straight on the server? That is an open hall, where cooks grab each other's ingredients, and versions collide. Or give each app a virtual machine: a separate house with its own plumbing. But every house carries a full operating system and its own kernel: a lot of overhead to isolate a single app.
Setting a limit
In practice, that meter is a single flag on docker run: a memory limit of 512 megabytes. Go past it, and the kernel can kill processes in the container.
So what does a container hold? No tiny computer. A fenced-in process, plus the files it needs, sharing the host's kernel.
Subscribe for the next one. Next time: Kubernetes. Who restarts your app when a machine dies?
Sources
Every fact in the video was checked against these when it was made.
- PyVideo, "Lightning Talk - The future of Linux Containers"
- opencontainers.org, About the Open Container Initiative
- Docker Docs, What is a container?
- Docker Docs, Docker Engine security
- namespaces(7), Linux man-pages 6.19
- cgroups(7), Linux man-pages 6.19
- Docker Docs, Resource constraints
- docker container run
- Docker Docs, Storage drivers