The idea
One server must run two Python apps. Shop needs Python 3.12, report needs Python 3.9, and both listen on port 8000. Installed side by side they clash: one Python version wins, and only one app can own port 8000.
A container is not a tiny computer. It is an ordinary process with walls round it, built by the Linux kernel. Inside, the app sees only its own files, its own processes and its own network. Each app gets one.
docker run asks the kernel for a fresh set of walls, called namespaces, then starts the app inside them. The last word, shop:1.0, names the image: a packed copy of every file the app needs.
What it sees: namespaces
The mount namespace gives each container its own file tree, taken from its image. Shop finds Python 3.12 at /usr/local/bin; report finds Python 3.9 at the same path. Neither can see the other's files.
Inside, os.getpid() prints 1: the app is the first process in its own PID namespace. The host's process list shows the same process as 4211. One process, two numbers, depending on who looks.
Each container has its own network, with its own ports, so both apps can listen on port 8000. -p 8080:8000 publishes one: a request to the host's port 8080 is forwarded to port 8000 inside shop.
What it uses: cgroups
Walls hide things, but they do not ration anything. Control groups (cgroups) do: --memory 256m caps shop at 256 MiB, and --cpus 0.5 gives it at most half of one CPU's time. Here it uses 120 MiB.
A bug makes shop eat memory. When it hits 256 MiB and cannot free any, the kernel's out-of-memory killer stops it. Report keeps running untouched: one app's bug cannot starve its neighbour.
Containers and VMs
Both containers run on the host's one Linux kernel. Nothing boots when a container starts: the kernel just starts a process with walls. That is why containers start about as fast as the app itself and many fit on one server.
A virtual machine is a whole operating system with its own kernel, running on a hypervisor. Its walls are stronger, but it must boot and it carries a full OS. Containers share one kernel, so they are lighter.
What happens
;; step 1/10 · clash shop needs Python 3.12, listens on :8000 report needs Python 3.9, listens on :8000 same server, no walls: one python3 on the PATH → one app breaks 2nd app on :8000 → OSError: Address already in use
Containers as described here are a Linux kernel feature. Docker Desktop on macOS and Windows runs them inside a small Linux virtual machine; Windows also has its own Windows containers. The PIDs 4211 and 4388 and the container ID 3f2a9c1e7b04 are example values; your machine prints its own. A process has one PID in each PID namespace it is visible in. The app is PID 1 only when the image starts it directly (exec form, CMD ["python", "app.py"]); in shell form, /bin/sh is PID 1.