Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run Different Linux OS in Docker Container?

Tags:

docker

Have been trying to learn Docker and one thing that puzzles me is how a different flavour of Linux (to the host OS) actually runs in the Docker container.

If we assume my Docker host is running RedHat and I start a container from an Ubuntu image then are the following true?:

  • logically speaking, if the Ubuntu image footprint is around 550MB then will the Docker Daemon actually download (from an image registry) 550MB worth of Ubuntu image in order to create the Container?
  • is the instance of Ubuntu running in the container essentially no different than if I had downloaded and installed the same version manually?

I'm aware that the Docker container shares the same kernel used by the host OS and that one of the fundamental points of Docker was its efficiency gains of the container using the underlying OS. So Im a bit confused about what actually happens when you start a Container created from a different Linux version than the host.

like image 342
JamieP Avatar asked Oct 13 '15 20:10

JamieP


People also ask

Can a Docker container run a different OS?

You can run both Linux and Windows programs and executables in Docker containers. The Docker platform runs natively on Linux (on x86-64, ARM and many other CPU architectures) and on Windows (x86-64). Docker Inc. builds products that let you build and run containers on Linux, Windows and macOS.

How can Docker run on different Linux distribution?

We can use docker to pull different images. And these images are different linux distribution. But no matter which linux distro docker is running on, docker can run these different linux distribution just like in a virtual machine. I know docker uses aufs to control different read-write access level.

Can Containers run on multiple OS?

Applications running in containers can be deployed easily to multiple different operating systems and hardware platforms. DevOps teams know applications in containers will run the same, regardless of where they are deployed.


2 Answers

I think this previous post may help you understand it a little more - Docker container isolation, does it care about underlying Linux OS?.

The crux of the matter is that if the Host OS is RedHat then it is the RedHat kernel which will be used by whatever build of Linux you run in your Docker container ie. Ubuntu in your example.

This comes down to understanding what the difference is between a Linux OS and a Linux Image. You will not be running a full Ubuntu OS inside the Docker Container but an image of Ubuntu.

For the purpose of your question think:-

OS = kernel + filesystem/libraries
Image = filesystem/libraries

The Ubuntu image running inside your Docker container is just the Ubuntu filesystem/libraries - it will not contain the Ubuntu kernel. This partly explains the efficiencies you get from a Docker container which is leveraging the Kernel (among other things) of the underlying Host.

like image 70
jacks Avatar answered Oct 17 '22 08:10

jacks


The Ubuntu image running inside the Docker container runs in what is called the user space for that container. This image can make kernel system calls to the RedHat host OS kernel (as part of transferring control from user space to kernel space for some user operations). Since the core kernel is common technology, the system calls are expected to be compatible even when the call is made from an Ubuntu user space code to a Redhat kernel code. This compatibility make it possible to share the kernel across containers which may all have different base OS images.

like image 29
Srikanth N Avatar answered Oct 17 '22 08:10

Srikanth N