Docker02: Docker core technology exploration (7) Add yum support to mydocker container

In order to add yum support to containers created through mydocker.sh, I encountered quite a few problems. Before describing these problems and solutions, it is necessary to talk about why yum support must be added.

The virtual system in our container starts with the support of the /bin/bash command. The support of each command including which , file, ldd , stace, etc., is to find missing files and dynamic information through ldd and strace The method of copying the library from the host system to the container system is not efficient, and it is difficult to fully satisfy various dependencies and operate normally. In fact, there are some hidden risks, because it is impossible to completely cover all running paths. .

With this understanding, the idea of ​​introducing the yum package installation management program is a matter of course. There are several things that need to be done:

 

1. Let the system in the container start the execution of the yum program normally.

In fact, it is to solve the problem of yum's python environment and /etc/yum.conf configuration environment.

The system in the container is very incomplete, and consistency cannot be satisfied in many places. One problem is that yum is able to link to the origin server, but lacks information about the CentOS version in the virtual system in our container. Mainly, two variables $releasever and $basearch are used in files such as CentOS-Base.repo in the /etc/yum.repos.d/ directory and cannot be assigned. Among them, $releasever is clearly 7, because all the file sources of our mirror are CentOS7 system, and the source of $basearch is the output result of the command arch. For this reason, let's solve the assignment problem of these two variables.

(a) Execute the command:

In order to do it once and for all, directly modify the files in the mirror. Execute the following commands in the etc/yum.repos.d/ directory of the mirror directory. $releasever also appears in /etc/yum.conf.

1  sudo sed -i -r 's/\$releasever/7/g'

This solves the assignment problem of $releasever.

(b) Find the arch command in the host system and add it to our image directory to provide support for the arch command for our container.

1 15:56:29 root@abc /etc/yum.repos.d#arch 2 x86_64

This solves the assignment problem of $basearch.

(3) If there is still a problem, the image of the yum command may be executed before these two variables are assigned. For example, the $releasever variable may appear in the /var/cache/yum directory.

yum still seems to have issues to be resolved.

 

2. The system in the container does not actually have any software packages installed, and the consistency of the software packages in the management system needs to be solved.

Although the dynamic libraries and related files of some of the basic software packages already exist in the container, they are not recognized in the software package management system, that is, they are not supervised by the software package management system, that is, the rpm system and the yum system. Supervision.

Simply put, there is no record of these packages in the rpm or rpmdb or yum database. These records exist in directories such as /var/lib/yum, /var/lib/rpm, /var/cache/yum, /var/cache/rpm, etc.

Yesterday, I made a mistake and took it for granted that these directories of the host system were completely copied into the container.

In this way, in the management system of software rpm and yum, the existence of these software packages has been "recognized". But as mentioned earlier, the real "files" of many software are not complete in the container, or even do not exist at all. Before copying database records, some software packages had no real names. Now, after copying database records, many software software packages have problems that have no real names.

Missing packages must first be force-installed using rpm -ivh --nodeps.

 

3. The system in the container does not support python completely.

The normal execution of yum depends on many packages of python. After investigation, it was found that at least one python-request-xxxx package was missing in the container, causing yum update and yum install to not work properly.

The reason for the error of yum update update is mainly due to the lack of python and more basic glib, libc and other packages. After forcibly installing these "basic" packages and python packages through the CentOS ISO image through rpm -ivh --nodeps, the yum update was successfully updated, and the subsequent yum installs were also successfully executed.

 

At this point, the normal yum package management system has been provided in our container, and the required software packages can be installed through the normal channels of yum later.

 

Guess you like

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