How containers works at low level?

Technology CommunityCategory: DockerHow containers works at low level?
VietMX Staff asked 3 years ago

Around 2006, people including some of the employees at Google implemented new Linux kernel level feature called namespaces (however the idea long before existed in FreeBSD). One function of the OS is to allow sharing of global resources like network and disk to processes. What if these global resources were wrapped in namespaces so that they are visible only to those processes that run in the same namespace? Say, you can get a chunk of disk and put that in namespace X and then processes running in namespace Y can’t see or access it. Similarly, processes in namespace X can’t access anything in memory that is allocated to namespace Y. Of course, processes in X can’t see or talk to processes in namespace Y. This provides kind of virtualization and isolation for global resources.

This is how Docker works: Each container runs in its own namespace but uses exactly the same kernel as all other containers. The isolation happens because kernel knows the namespace that was assigned to the process and during API calls it makes sure that process can only access resources in its own namespace.