This topic describes how to resolve the following issue: Docker cannot be installed by using third-party YUM repositories, such as Docker Community Edition (Docker-CE) and Extra Packages for Enterprise Linux (EPEL) repositories, on an Elastic Compute Service (ECS) instance that runs Alibaba Cloud Linux 2.
Problem description
When you use third-party YUM repositories (such as Docker-CE and EPEL repositories) that are compatible with CentOS 7 and run the yum install docker-ce
command to install Docker on an Alibaba Cloud Linux 2 instance that meets the following conditions, Docker cannot be installed and the following error message is returned:
The instance uses the Alibaba Cloud Linux 2.1903 LTS 64-bit image.
The image used by the instance is aliyun_2_1903_x64_20G_alibase_20210325.vhd or earlier.
Loaded plugins: fastestmirror, langpacks, update-motd
Loading mirror speeds from cached hostfile
* epel: mirror.sjtu.edu.cn
https://mirrors.aliyun.com/docker-ce/linux/centos/2.1903/x86_64/stable/repodata/repomd.xml: [Errno 14] HTTPS Error 404 - Not Found
Trying other mirror.
Downloading packages:
docker-ce-20.10.6-3.el7.x86_64 FAILED
https://mirrors.aliyun.com/docker-ce/linux/centos/2.1903/x86_64/stable/Packages/docker-ce-20.10.6-3.el7.x86_64.rpm: [Errno 14] HTTPS Error 404 - Not Found
Trying other mirror.
docker-ce-rootless-extras-20.1 FAILED
https://mirrors.aliyun.com/docker-ce/linux/centos/2.1903/x86_64/stable/Packages/docker-ce-rootless-extras-20.10.6-3.el7.x86_64.rpm: [Errno 14] HTTPS Error 404 - Not Found
Trying other mirror.
Error downloading packages:
3:docker-ce-20.10.6-3.el7.x86_64: [Errno 256] No more mirrors to try.
docker-ce-rootless-extras-20.10.6-3.el7.x86_64: [Errno 256] No more mirrors to try.
Cause
Third-party YUM repositories are compatible only with CentOS 7. The $releasever
value of Alibaba Cloud Linux 2 is different from that of CentOS 7. As a result, the Docker package cannot be downloaded because the resolved YUM repository addresses are invalid.
When YUM installs Docker-CE, YUM obtains the version number ($releasever
value) from the system and replaces the $releasever
value in the baseurl of the corresponding YUM repository with the obtained version number to obtain required data. The $releasever
value of CentOS 7 is 7, and the $releasever
value of Alibaba Cloud Linux 2 is 2.1903. As a result, the baseurl is resolved to a non-expected address for Alibaba Cloud Linux 2, and YUM cannot obtain the required data from the address.
Solutions
Use one of the following methods to resolve the issue:
Perform the operations described in Solution 1: Change the $releasever value to change the value of
$releasever
.Perform the operations described in Solution 2: Use a plug-in to change the $releasever value to install the yum-plugin-releasever-adapter plug-in, and then use the plug-in to change the value of $releasever.
In the examples, the Docker-CE repository is used. You can perform the same operations for other YUM repositories.
Solution 1: Change the $releasever value
Log on to the Linux instance.
For more information, see Connect to a Linux instance by using a password or key.
Run the following command to modify the
/etc/yum.repos.d/docker-ce.repo
configuration file:vim /etc/yum.repos.d/docker-ce.repo
Press the
I
key to enter the edit mode. In the docker-ce.repo file, find all repositories for which enabled=1 is displayed, and change the$releasever
value in the baseurls of the repositories to 7, as shown in the following figure.Press the
Esc
key, enter:wq
, and then press Enter to save and close the configuration file. Re-install the Docker software.
Solution 2: Use a plug-in to change the $releasever value
Install the yum-plugin-releasever-adapter plug-in to automatically change the $releasever
value from 2.1903 to 7.
Check whether the instance supports the yum-plugin-releasever-adapter plug-in.
The following table describes the current versions of the yum-plugin-releasever-adapter plug-in and the third-party repositories that are supported by default.
Plug-in version
Third-party repository supported by default
Limits on the plug-in
1.0-1.3
Docker-CE and EPEL
To use the plug-in, make sure that the following requirements are met:
The operating system is Alibaba Cloud Linux 2.
Run the following command to check whether the plus repository exists:
cat /etc/yum.repos.d/AliYun.repo |grep -A3 plus
If a command output similar to the following one is returned, the plus repository exists.
Log on to the Linux instance.
For more information, see Connect to a Linux instance by using a password or key.
Run the following command to install the yum-plugin-releasever-adapter plug-in. The plug-in changes the
$releasever
values of the Docker-CE and EPEL repositories.yum install yum-plugin-releasever-adapter --disablerepo=* --enablerepo=plus
If you do not need to change the value of $releasever for other YUM repositories, install the Docker software after the plug-in is installed. If you need to change the value of $releasever for other YUM repositories, perform the following operations:
Run the following command to go to a specified directory:
cd /etc/yum/pluginconf.d/
Run the following command to modify the
releasever-adapter.conf
configuration file: If you want to add other YUM repositories, append the.repo
file names of the YUM repositories to the includes field. Separate the file names with commas (,).vim releasever-adapter.conf
A command output that is similar to the following one is displayed:
[main] enabled=1 hostfilepath=timedhosts.txt [releasevermapping] release_dict={'2.1903':'7', '3':'8'} [reposlist] includes=docker-ce.repo, epel.repo
NoteThe following parameters are used in the configuration file:
[main]: the main control part of the plug-in that is used to enable or disable the plug-in. If enabled is set to 1, the plug-in is enabled. If enabled is set to 0, the plug-in is disabled.
[releasevermapping]: the mappings between the
$releasever
values that you want to change. 2.1903 is mapped to 7, and 3 is mapped to 8.[repolist]: the list of repositories that you want to modify. If you want to add other YUM repositories, append the
.repo
file names of the repositories to the includes field. Separate the file names with commas (,).
A
.repo
file contains multiple repositories, and each repository has a system-wide unique name. For example, thedocker-ce-stable
anddocker-ce-stable-debuginfo
repositories exist at the same time in thedocker-ce.repo
file.Make sure that each .repo file name added to the
releasever-adapter.conf
configuration file is the prefix of the names of the repositories that are contained in the .repo file. For example, thedocker-ce.repo
file contains thedocker-ce-stable-debuginfo
anddocker-ce-stable
repositories that share thedocker-ce
prefix.
Save the configuration file and run the following command to install the Docker software by using the Docker-CE and EPEL repositories.
yum install docker-ce