134

I'm not certain that I'm asking the right question... but while I have been reading everything docker that I can get my hands on I see that I can install Docker on Ubuntu 12.04 (for example) and then I can install a Fedora container or a different version of ubuntu? (there is an example where the user installed busybox in the container.)

And of course I could be completely wrong.

But it would be my expectation that there was a ephemeral connection between the base system and the container.

restated: what is the relationship between the host OS and the container base image's OS?

Richard
  • 10,122
  • 10
  • 42
  • 61

3 Answers3

107

As mentioned by BraveNewCurrency, the only relationship between the host OS and the container is the Kernel.

It is one of the main difference between docker and 'regular' virtual machines, there is no overhead, everything takes place directly within the host's kernel.

This is why you can run only Linux based distribution/binaries within the container. If you want to run something else, it is not impossible, but you would need some kind of virtualization within the container (qemu, kvm, etc.)

Docker manage images that are the file system representation. You can install any linux distribution or simply put binaries.

Indeed, for the convenience of the example, we often rely on the base images, but you could also create your image without any of the distribution libraries/binaries. That way you would have a really tiny yet functional container.

One more point regarding the distributions: as the kernel is still the kernel of the host, you will not have any specific kernel module/patches provided by the distribution.

creack
  • 116,210
  • 12
  • 97
  • 73
  • 2
    so if the host OS is Ubuntu then the container is going to be Ubuntu too? – Richard Sep 18 '13 at 05:12
  • 22
    The container's kernel is going to be the one from ubuntu, but nothing more. You can run easily centos, archlinux, debian or any other linux based distribution as containers. – creack Sep 18 '13 at 17:15
  • restated ... while being a popular host OS is probably better, it's not required so long as the *KERNEL* supports the required features and docker has a working API or path to those features. – Richard Sep 18 '13 at 19:24
  • 40
    Although this information may be stated directly/indirectly on the docker website, I really feel they should make this a bit clearer. I had worked my way through the homepage, overview, the interactive tutorial, and most of the basic tuts. Despite this I was confused on this topic, and was starting to assume that the best performance from docker (based on the architecture diagrams from the site) would require a match on the host and container OS. I am new to the concept of the "linux kernel" so this was not immediately obvious to me. Knowing this instantly makes docker double as bad-ass. – ctrlplusb Oct 19 '14 at 09:03
  • 2
    Docker is a pretty complex project that leverage advance features. At some point, we assume the user has some knowledge like the difference between operating system and distribution. If you think it would add value, the documentation is open source and you can submit a pull request. – creack Oct 19 '14 at 09:08
  • Thanks for that @alph486 - Docker is an amazing piece of kit, and despite what some may think, I believe it has genuine case to be attractive to users who wouldn't be considered "power users". Some of the simpler things that docker can provide can literally transform the virtual landscape for many very quickly. I really feel that this shouldn't be overlooked, and clear and easy instructions for what may seemingly be a simple use-case for others will only expand adoption and possibly provide a great support for continued growth of Docker. I will give this book a go. Thanks for the recommend. – ctrlplusb Oct 31 '14 at 16:42
  • Wouldn't there be over head if say I install Debian Distribution Docker image which contain a specific version of a Linux Kernel? Now you have a container with a Kernel, on top of another kernel(The docker host's kernel). Or am I missing something? – mskw Jan 30 '16 at 04:36
  • Even if your image contains a kernel, Docker will not execute it unless you try to effectively "boot" inside the container. – creack Jan 30 '16 at 15:22
  • 5
    This seems to indicate that only the user-space parts of an OS (libraries, commands, applications) can be containerized. If the application requires a different kernel revision (e.g. 3.10 vs. 4.9) then it may not be able to run in a container. Is that right? – David C. Jul 13 '17 at 16:25
  • 4
    That is correct. However, you can containerize an actual virtual machine (e.g. qemu) and run any kernel there. – creack Jul 13 '17 at 16:52
  • So if one containerize an application with no OS , would it be possible to get a shell prompt on the container , have a file-system and so on ? If so , how? I mean it has a kernel , but doesn't have the OS, right ? – John Doe Dec 25 '18 at 10:19
28

Literally, the only thing they have in common is the kernel. Their whole world (file system) is in the docker container.

BraveNewCurrency
  • 12,654
  • 2
  • 42
  • 50
1

There is another consideration - even if the both kernels are the same, there is a problem if the host OS does not support Docker, like RHEL 6: https://access.redhat.com/solutions/1378023

So you won't be able to spin up a container on RHEL 6, even if the image is a Linux one.

flow2k
  • 3,999
  • 40
  • 55