Base image understanding in Docker image

The base image has two meanings:

  1. Build from scratch without dependencies on other mirrors.

  2. Other images can be extended based on it.

Therefore, what can be called base images are usually Docker images of various Linux distributions, such as Ubuntu, Debian, CentOS, etc.

Let's take CentOS as an example to examine what the base image contains.
Download the image:

docker pull centos

View mirror information:

52.png

The image size is less than 200MB.

Wait a moment!
A CentOS is only 200MB?
Usually we install a CentOS with at least a few GB, how can it be only 200MB!

I believe this is a question that almost all Docker beginners will have, including myself. Let us explain this problem below.

The Linux operating system consists of kernel space and user space. As shown below:

rootfs

The kernel space is the kernel. The bootfs file system will be loaded when Linux starts, and then the bootfs will be unloaded.

The file system of user space is rootfs, which contains familiar directories such as /dev, /proc, /bin.

For the base image, the bottom layer directly uses the host's kernel, and you only need to provide rootfs.

For a stripped-down OS, the rootfs can be small and only need to include the most basic commands, tools, and libraries. Compared with other Linux distributions, the rootfs of CentOS is already bloated, and alpine is less than 10MB.

In addition to rootfs, the CentOS we usually install will also install a lot of software, services, graphical desktops, etc. It is not surprising that it requires several GB.

The base image provides a minimally installed Linux distribution .

Here is the content of the Dockerfile for the CentOS image:

The tar package added to the image by the ADD command on the second line is the rootfs of CentOS 7. When making an image, the tar package will be automatically decompressed to the / directory to generate /dev, /proc, /bin and other directories.

Note: The Dockerfile can be viewed on the image description page on Docker Hub.

Supports running a variety of Linux OS

The main difference between different Linux distributions is rootfs.

For example, Ubuntu 14.04 uses upstart to manage services and apt to manage packages; while CentOS 7 uses systemd and yum. These are all differences in user space, the Linux kernel is not much different.

Therefore, Docker can support multiple Linux images at the same time, simulating multiple operating system environments.

The upper layer of Debian and BusyBox (an embedded Linux) provides their own rootfs, and the bottom layer shares the kernel of Docker Host.

It should be noted here that:

      1. The base image is only consistent with the distribution in user space, and the kernel version is different from the distribution.
        For example, CentOS 7 uses the 3.xx kernel. If the Docker Host is Ubuntu 16.04 (such as our experimental environment), then the CentOS container actually uses the Host 4.xx kernel. 

        ① The host kernel is 4.4.0-31
        ② Start and enter the CentOS container
        ③ Verify that the container is CentOS 7
        ④ The kernel version of the container is the same as the Host

      2. The container can only use the host's kernel and cannot be modified.
        All containers share the kernel of the host, and there is no way to upgrade the kernel in the container. If the container has requirements on the kernel version (for example, the application can only run under a certain kernel version), it is not recommended to use the container. In this scenario, a virtual machine may be more suitable.

 

Reprinted from https://www.cnblogs.com/kb342/p/7649598.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324500203&siteId=291194637