Under the Hood
When a container is launched via the Docker CLI, the following steps are executed:-
CLI to REST API Conversion:
The Docker client translates the command into a RESTful API call that is sent to the Docker daemon. -
Image Verification:
The Docker daemon checks if the specified image is already stored on the local system. If it isn’t found, the image is downloaded from Docker Hub. -
Container Creation:
After the image is available, the Docker daemon instructs containerd to start the container. Containerd converts the image into an OCI-compliant bundle and passes it to the containerd shim. -
Runtime Invocation:
The containerd shim calls the container runtime (runc by default) to create the container. Runc interacts with the system’s namespaces and cgroups to establish an isolated environment.
The conversion to an OCI bundle provides a standardized way to encapsulate container images, enabling compatibility across various container runtimes.
The Role of runc
runc is the default container runtime implementing the standards defined by the Open Containers Initiative (OCI). When runc is installed, containers can be created directly using its CLI without relying on Docker’s additional management features. For example, you could start a container with:Alternative Container Runtimes
Besides runc, specialized container runtimes are available for enhanced isolation, particularly through sandboxing technologies like Kata Containers and gVisor. Key alternatives include:- Kata Containers: Implements its own runtime to provide an extra layer of isolation.
- gVisor: Uses a runtime known as runsc to offer secure container sandboxing.
kata for Kata Containers and runsc for gVisor—to create the container.
Conclusion
In this lesson, we detailed the steps involved in launching a container with Docker—from checking and downloading the image to converting it into an OCI bundle, and finally creating the container using either runc or an alternative runtime.Stay tuned for our next lesson, where we cover installing gVisor on Kubernetes nodes and deploying sandboxed containers within Kubernetes pods.