Table of contents
Have you ever wondered how docker works in a local machine? What is namespacing and cgroups? In this article, we’re going to walk through how Docker works on a local computer that does not have linux as it’s primary Operating system.
How Docker Works In A Local Machine
There are two primary pieces of technology we need to talk about, first – is the namespacing in Linux kernels and the second is cgroups. Though we will not go into details in this article, it is important to know that these two are key in Docker operations.
Namespacing
Namespacing is a technique (and technology) which containers use to create an abstraction of the underlying host. Namespacing maps a portion of the kernel’s namespace to provide isolation between processes running in isolated “containers”. Let’s take a quick look at what namespaces are. Namespaces are kernel objects which allow the whole of the kernel to be divided into smaller parts.
Namespaces are always stored in files in /proc . More information on namespaces can be found here.
Cgroups
Once again, it is a technology that provides control over system-level resources by grouping them hierarchically.
The second piece is Linux Control Groups – also known as LXC containers – which are used with Docker’s cgroups technology to provide resource allocation to processes that are running within “containers”.
More information on cgroups can be found here.
This shows how docker utilizes namespaces and groups on linux.
If both namespaces and cgroups are linux specific commands, how does docker run on Mac/Windows?
Docker uses another driver by the name of Kernel Streaming (Kernel Streaming is a technology that allows sharing of kernel memory between processes.) This driver is embedded into Docker. As such, it enables containers to run as any other process on that host machine (Linux).
How can you check which Linux version is running as a virtual machine to host the Docker on your local machine? – You can simply do the below.
Open up terminal and type.
docker version
The OS shows the virtual machine that Docker containers are running on. As you can see, it shows linux, even if I am currently running this on MacOs.
Conclusion
In a very basic sense, that is how docker runs on your machine, to learn more about basic docker commands, see this article.