How does Docker run a Linux kernel under macOS host?

LinuxMacosDockerLinux Kernel

Linux Problem Overview


I installed Docker on my macOS Sierra as follows. Note I don't have VirtualBox installed.

brew cask uninstall virtualbox
brew cask install docker

My macOS details.

$ uname -a
Darwin m-C02QG7TRG8WN.local 16.5.0 Darwin Kernel Version 16.5.0: Fri Mar  3 16:52:33 PST 2017; root:xnu-3789.51.2~3/RELEASE_X86_64 x86_64

$ docker version
Client:
 Version:      17.03.1-ce
 API version:  1.27
 Go version:   go1.7.5
 Git commit:   c6d412e
 Built:        Tue Mar 28 00:40:02 2017
 OS/Arch:      darwin/amd64

Server:
 Version:      17.03.1-ce
 API version:  1.27 (minimum version 1.12)
 Go version:   go1.7.5
 Git commit:   c6d412e
 Built:        Fri Mar 24 00:00:50 2017
 OS/Arch:      linux/amd64
 Experimental: true

Once I run Docker from launchpad, I am able to run Docker containers.

$ docker run -it ubuntu
root@2351d4222a4e:/# uname -a
Linux 2351d4222a4e 4.9.13-moby #1 SMP Sat Mar 25 02:48:44 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

My question is how does Docker manage to run a Linux kernel within macOS? I thought Docker would at least require boot2docker or some other such Linux kernel running so that it can create the Ubuntu's filesystem with the help of it. But the above output seems to indicate that it is not so. Where does the Linux kernel come from then?

Linux Solutions


Solution 1 - Linux

While the other answers are correct about the hypervisor, they don't answer your specific question.

The answer is "Docker [Desktop] for Mac" does run a Linux host VM with a replacement for boot2docker - LinuxKit developed and maintained by Docker for the purpose of making lightweight distributions.

https://blog.docker.com/2017/04/introducing-linuxkit-container-os-toolkit/

The uname you saw didn't have the keyword in it, but it seems to be included now, e.g. from Docker for Mac 18.03.1 I see:

Linux a8e079429a51 4.9.87-linuxkit-aufs #1 SMP Wed Mar 14 15:12:16 UTC 2018 x86_64 Linux

You can see links to the included versions on the release pages. https://docs.docker.com/docker-for-mac/release-notes/

So it's not so different from the old days Docker Machine + VirtualBox + boot2docker,

for the new days, it's just the provisioning is done internally by "Docker [Desktop] for Mac" and VirtualBox is replaced by Apple's Hyperkit, and the "default VM" is a bit more tucked away.

Solution 2 - Linux

The early version Docker used VirtualBox to run virtual machine for Docker. Since June 2016, the way to run Docker on Mac and Windows became much simpler, there's the official release introduction blog for Docker on Mac/Windows, and there's also some introduction from docker mac website:

> Docker for Mac is a complete development environment deeply integrated with the MacOS Hypervisor framework, networking and filesystem.

And with the structure looks like:

enter image description here

Solution 3 - Linux

Docker is using Apple's Hypervisor Framework: https://developer.apple.com/reference/hypervisor

More reading on the Docker blogs for when then came out last year: https://blog.docker.com/2016/05/docker-unikernels-open-source/

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLone LearnerView Question on Stackoverflow
Solution 1 - LinuxscipilotView Answer on Stackoverflow
Solution 2 - LinuxshizhzView Answer on Stackoverflow
Solution 3 - LinuxDigicoderView Answer on Stackoverflow