且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么docker有能力运行不同的linux发行版?

更新时间:2023-02-25 19:23:37

因为内核是相同的。



所有linux发行版的共同点,以及为什么被称为linux,是因为它们都使用linux内核。



容器与主机共享相同的内核,这就是为什么您可以在Ubuntu主机上运行Arch映像。



以下是Linux的概述。 / p>

内核是处理与硬件通信的操作系统的一部分。这是操作系统的最低级别。以下是内核的主要功能列表:




  • 内存管理

  • 网络管理

  • 设备驱动程序

  • 文件管理

  • 进程管理



所以当你使用容器你只能访问主机的内核,因为它是与硬件通信的唯一部分,只要你的操作系统使用好的 syscall ,您可以在容器内运行任何linux分发。 (这是您不能在容器内使用Windows的原因:它不使用相同的 syscall )。


We can use docker to pull different images. And these images are different linux distribution. But no matter which linux distro docker run on, docker can run these different linux distribution jsut like in a virtual machine.

I know docker use aufs to control diffrent read-write access level. So it can reuse some file on host machine. But how can docker run a apt-get command in a container when I run docker in a arch linux ? Is the imagegs contain the apt-get binary? But different linux distribution has different libs and software version. Even the configuration file are differnt.How docker can "run" a ubuntu in a arch linux?

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).