Linux – Running multiple ubuntu (or other distro) inside Docker containers on CoreOS, is this efficient

containerscoreosdockerlinuxlinux-kernel

From what I have read I believe CoreOS to be a bare-bones Linux distribution which essentially facilitates running Docker containers that contain any applications or services that you require.

From the CoreOS documentation I gather that the intention is that you separate most of your services into separate Docker containers so that you can then scale horizontally, allowing fleet to manage the container over multiple nodes.

Where I am getting a little confused is when you want to run a service that needs a specific linux userland (e.g. apache running on Ubuntu or Fendora or something). Say for example I have a container with Ubunutu and apache running on it, and I want another container running a Samba instance (also on Ubunutu), am I not effectively running 2 copies of Ubuntu, with all the overheads of running those OS's?

I think I am very likely mis-understanding how containers work – if I run Ubuntu in a container, then presumably I am sharing the CoreOS kernel, and only the "userland" part of the OS is "running"?

So then might question might be, is running the kernel the expensive part of running an OS? So when you are running virtual machines you are loosing alot of resource by not only having to simulate hardware, but also running multiple kernels?

Best Answer

Yes, you're running multiple user-lands but only one kernel, which means the kernel has the full view of all memory management and can most efficiently split it up between the running containers, based on their CPU shares, etc. To the kernel, a container is just another process that needs access to the hardware. Each container process just happens to use a specific user-land, which is just a name-spaced pile of files on disk when it comes down to it.