What happens, step by step, when you run `docker run -p 8080:80 nginx`?
IntermediateConceptContainers, VMs & Isolation Internals
Answer
- CLI sends the request to
dockerdover/var/run/docker.sock. - If
nginx:latestis not local, dockerd pulls manifest and layers from the registry. - Layers are unpacked via containerd snapshotter and an overlay mount is prepared with a new writable layer.
- dockerd creates the container config, network namespace, veth pair attached to
docker0, and an iptables DNAT rule for 8080 to the container IP:80. - containerd launches
containerd-shim, which callsruncto create namespaces/cgroups and exec the entrypoint. - runc exits; the shim stays as the parent and holds stdio.
More on Containers, VMs & Isolation Internals
What is a container, in one sentence?BeginnerHow do containers differ from virtual machines?BeginnerCan a Linux container run a Windows application, or the reverse?IntermediateWhat are Linux namespaces? Name the ones Docker uses.BeginnerWhat are cgroups and what do they do for containers?BeginnerWhat is PID 1 in a container and why does it matter?Intermediate