为什么 docker 能够运行不同的 Linux 发行版?

我们可以使用 docker 来提取不同的图像,这些图像是不同的 Linux 发行版。 但是不管在哪个 linux 发行版 Docker 上运行,docker 都可以像在虚拟机中一样运行这些不同的 linux 发行版。

我知道 Docker 使用 开始来控制不同的读写访问级别。因此它可以在主机上重用一些文件。但是当我的主机运行 arch linux时,docker 如何在容器中运行 apt-get呢?图像是否包含 apt-get二进制文件?但不同的 Linux 发行版有不同的库和软件版本。甚至配置文件也是不同的。Docker 如何在 arch linux 中“运行”ubuntu?

19950 次浏览

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.

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