# Docker Container Anatomy

How a Docker container is built from stacked image layers, then walled off and limited by the Linux kernel's namespaces and cgroups\.

By Numa

Topic: Computing, AI &amp; Electronics

[Open the interactive Jig](https://ask.jig.com/j/lZ0PJxwvxfcu)

## Transcript

### 1. Boxes that changed the world

From the late 1950s, one standard steel box changed shipping: any crane, ship or truck could carry it, whatever was inside\. In 2013 Docker did the same for software\. It packs a program and everything it needs into a standard box called a container\. Drag the scene to look around\.

A 20\-foot shipping container is about 6 metres long, 2\.4 metres wide and 2\.6 metres tall\.

### 2. An image is a stack of layers

Every container starts from an image: a read\-only package of files\. It is built in layers, one for each line of a recipe file called a Dockerfile\. A base system comes first, then a language runtime, libraries and finally the app's own code\.

If you change only your code, only the top layer has to be rebuilt\.

### 3. Pull from a registry

Images are stored in a registry, a shared library of images\. Docker Hub is the best known\. Pulling copies an image's layers onto your computer, and layers you already have are not downloaded again\.

In March 2024 Docker said Docker Hub served about 25 billion pulls a month\.

### 4. Run: one thin writable layer

A container is a running copy of an image\. Docker lays one thin writable layer on top, and every change the program makes lands there\. The image layers below never change, so many containers can share them\.

Delete the container and its writable layer goes with it\. Data you want to keep goes in a volume\.

### 5. Walls made by the kernel

The kernel is the core of the operating system\. It gives each container its own private view of programs, network and files, called namespaces\. Control groups, or cgroups, set limits on how much processor time and memory each container may use\.

The bars show each container's use of processor and memory\. The red line is its limit\.

### 6. Not a tiny computer

Containers share the host's one Linux kernel\. They are ordinary programs, kept apart by the kernel\. A virtual machine is different: each one carries a whole guest operating system of its own\. Switch between them and compare\.

That is why a container usually starts much faster and uses less memory than a virtual machine\.

### 7. Build once, run anywhere

The same image runs on a laptop, on a server in a data centre or in the cloud, as long as Docker and a Linux kernel are there\. "It works on my machine" stopped being an excuse\. Docker did not invent containers, but it made them easy to build, share and run\.

Docker was first shown in a five\-minute talk at PyCon in March 2013\.

### 8. The whole anatomy

From the bottom up: the computer, one shared Linux kernel, Docker Engine, and the containers\. Each container is a stack of read\-only image layers with one thin writable layer on top, walled by namespaces and kept to its limits by cgroups\.
