Article directory
foreword
To install Docker Engine on CentOS, a maintenance release of CentOS 7, CentOS 8(stream) or CentOS 9(stream) is required
This installation environment:
- VMware 16.2.2
- Linux system version:
CentOS Linux release 7.9.2009 (Core)
- For convenience, I
root
installed it as a user. If you use a non-root
user, some commands need to be addedsudo
Install
Enable centos-extras repository
It's on by default, but if you disabled it, you'll need to re-enable it
The specific method is as follows:
Check whether centos-extras is enabled
# yum repolist all
The picture above shows that extras
it is not turned on
Enter the following command on the command line
# vim /etc/yum.repos.d/CentOS-Base.repo
The content is as follows
# ...省略其他内容
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
enabled=0
Set enabled
the value of1
# ...省略其他内容
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
enabled=1
Press keyesc
, input :wq
save and exit
And enter the following command on the command line to clear the cache and create a new metadata cache
# yum clean all
# yum makecache
If there are problems that may occur during the process
/var/run/yum.pid 已被锁定
, you canctrl+c
exit first and try again later
Check again whether centos-extras is enabled
# yum repolist all
The display results are as follows:
uninstall old version
If you have installed an old version before docker
, you need to remove the previously installed dependencies first
Older versions of
Docker
were calleddocker
ordocker-engine
# yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
/var/lib/docker/
, including images, containers, volumes, and networks, will be preserved. The Docker Engine package is now called docker-ce
- docker-ce is an open source project maintained by docker company, and it is a free container product based on the moby project
- docker-ee is a closed-source product maintained by docker company and a commercial product of docker company
Installation method selection
docker-ce
There are many ways to install, such as manual installation by downloading rpm
the package, and 自动化脚本
quick installation.
It is recommended to install through the used Docker
repository. This installation method is also convenient for our future upgrades. This article also uses this installation method as an example.
rpm
Package address https://download.docker.com/linux/centos/
自动化脚本
address https://get.docker.com/
repository install docker
Docker Engine
Before installing for the first time on a new host , Docker
the repository needs to be set up. After that, we can install and update from the repository Docker
.
Set up the repository
Install yum-utils
the package (which provides yum-config-manager
the program), then set up the repository
# yum install -y yum-utils
# yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
Install Docker Engine
Install the latest version Docker Engine
, containerd
and Docker Compose
, if you want to install a specific version, you can go to the official website to view the installation process
# yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin
The official documentation mentions:
If prompted to accept the GPG key, verify that the thumbprint matches
060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35
and accept it if so.
But I didn't get this prompt when I installed it.
After the command is executed it installs Docker
but does not start Docker
.
It also creates a docker
group , but by default it doesn't add any users to that group.
# cat /etc/group
Start and verify Docker
# systemctl start docker
#此命令会下载测试镜像并在容器中运行它。当容器运行时,它会打印一条消息并退出
# docker run hello-world
The output is as follows:
Uninstall Docker Engine
- Uninstall Docker Engine, CLI, Containerd and Docker Compose packages
# yum remove docker-ce docker-ce-cli containerd.io docker-compose-plugin
-
Images, containers, volumes, or custom configuration files on the host are not automatically deleted.
Delete all images, containers and volumes:
# rm -rf /var/lib/docker
# rm -rf /var/lib/containerd
Any edited configuration files must be manually deleted
Configure Mirror Accelerator
Configure Alibaba Cloud Image Accelerator
https://cr.console.aliyun.com/cn-heyuan/instances/mirrors
Add the operation document according to the above figure, and then restartdocker
# systemctl daemon-reload
# systemctl restart docker
Check whether the accelerator is configured successfully
# docker info
If there is the following content in the output information:
Registry Mirrors:
https://[你配置的域名]/
Indicates that the configuration is successful
Summarize
At this point, Docker
the relevant installation tutorials are over.