90

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. So it can reuse some file on the host machine. But how can docker run apt-get in a container when my host runs arch linux? Does the image contain the apt-get binary? But different linux distribution have different libs and software version. Even the configuration file are different.How can docker "run" ubuntu in a arch linux?

edi9999
  • 19,701
  • 13
  • 88
  • 127
atupal
  • 16,404
  • 5
  • 31
  • 42
  • 4
    Tagged as theory. It's a valid question about OS and Docker low level implementation. – Regan Aug 22 '14 at 10:00
  • 2
    possible duplicate of [What is the relationship between the docker host OS and the container base image OS?](http://stackoverflow.com/questions/18786209/what-is-the-relationship-between-the-docker-host-os-and-the-container-base-image) – Regan Aug 22 '14 at 15:01

2 Answers2

108

Because the kernel is the same.

The common point of all linux distributions, and why they are called linux, is because they all use the linux kernel.

Containers share the same kernel as the host, that's why you can run an Arch image on a Ubuntu host.

Here's an overview of Linux.

The kernel is a part of the operating system that handles communication with the hardware. It's the lowest level of the operating system. Here is a list of the main functions of the kernel:

  • memory management
  • network management
  • device driver
  • file management
  • process management

So when you use a container you only have access to the kernel of the host, since it's the only part that communicates with hardware, as long as your OS uses the good syscall, you are able to run any linux distribution inside your container. (This is the reason you can't use Windows inside a container: it's not using the same syscall).

Brad Cupit
  • 6,530
  • 8
  • 55
  • 60
Regan
  • 8,231
  • 5
  • 23
  • 23
  • 8
    So running an ubuntu docker image is running everything that ubuntu is doing atop the linux kernel. Isn't it? – lajarre Jan 16 '15 at 10:51
  • 7
    @lajarre Not exactly. It's not running everything (although it technically can), the basic ubuntu image run the minimum needed to make ubuntu work. – Regan Jan 18 '15 at 16:17
  • 12
    @Regan, how does docker handle the differences between different linux kernel versions? – Hammer Mar 24 '16 at 05:27
  • 5
    @Hammer Not at all. All containers run on the same kernel. The largest differences between distributions is the userland (application, libraries, filesystem, package manager). Each container contains its own version of it. But there are exceptions, like the [Redis database](https://redis.io/topics/admin), where the kernel differences indeed matter. – MauganRa Aug 30 '17 at 08:31
  • this answer accidentally reverses the role of what the OP had for Arch and Ubuntu. – Tommy Oct 09 '18 at 14:00
5

Yes the images will have to contain apt-get for you to be able to run apt-get. Each image can have different software installed inside it. So you could install an Arch docker image or an ubuntu image for example. You can search for public images using the following command.

docker search <your search term>

so to search for an ubuntu image you could use

docker search ubuntu

I'd recommend following through the docker tutorial and carefully reading all the instructions and links on the left as you go through.

Jim Jeffries
  • 9,841
  • 15
  • 62
  • 103