Linux namespaces – the foundation of LXC
Namespaces are the foundation of lightweight process virtualization. They enable a process and its children to have different views of the underlying system. This is achieved by the addition of the
unshare() andsetns()system calls,and the inclusion of six new constant flags passed to the
clone(),unshare(), andsetns()system calls:clone(): This creates a new process and attaches it to a new specified namespaceunshare(): This attaches the current process to a new specified namespacesetns(): This attaches a process to an already existing namespace
There are six namespaces currently in use by LXC, with more being developed:
Mount namespaces, specified by the
CLONE_NEWNSflagUTS namespaces, specified by the
CLONE_NEWUTSflagIPC namespaces, specified by the
CLONE_NEWIPCflagPID namespaces, specified by the
CLONE_NEWPIDflagUser namespaces, specified by the
CLONE_NEWUSERflagNetwork namespaces, specified by the
CLONE_NEWNETflag
Let’s have a look at each in more detail and see some userspace examples, to help us better understand what happens under the hood.