docker的安装
CentOS 系统安装docker服务
[root@10-13 backup]# cat /etc/redhat-release
CentOS Linux release 8.2.2004 (Core)
我们这里CentOS系统,直接参考官方文档关于docker在CentOS系统上的安装:
https://docs.docker.com/engine/install/centos/
系统要求:
To install Docker Engine, you need a maintained version of CentOS 7 or 8. Archived versions aren’t supported or tested.
CentOS 7 或者8,说的很清楚了
Uninstall old versions
删除旧的版本,源文档是有sudo的,这里直接登录root用户操作的,去掉sudo ,直接执行yum命令
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
Installation methods
安装方法
You can install Docker Engine in different ways, depending on your needs:
1)设置docker仓库,从Docker参考安装(也就是从yum源安装)
Most users set up Docker’s repositories and install from them, for ease of installation and upgrade tasks. This is the recommended approach.
2)下载RPM安装包手动安装
Some users download the RPM package and install it manually and manage upgrades completely manually. This is useful in situations such as installing Docker on air-gapped systems with no access to the internet.
3)采用自动脚本安装
In testing and development environments, some users choose to use automated convenience scripts to install Docker.
我们采用第一种方法安装
1)
yum install -y yum-utils
CentOS-8 - PowerTools 93 B/s | 38 B 00:00
Error: Failed to download metadata for repo ‘PowerTools’: Cannot prepare internal mirrorlist: No URLs in mirrorlist
报错,上网查,得知原因
CentOS团队终于从官方镜像中移除CentOS 8的所有包。
CentOS 8已于2021年12月31日寿终正非,但软件包仍在官方镜像上保留了一段时间。现在他们被转移到https://vault.centos.org
[root@10-13- backup]# sed -i -e “s|mirrorlist=|#mirrorlist=|g” /etc/yum.repos.d/CentOS-*
[root@10-134 backup]#
[root@10-13- backup]#
[root@10-14 backup]# sed -i -e “s|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g” /etc/yum.repos.d/CentOS-*
[root@10-13-53-194 backup]#
再次运行,yum install -y yum-utils,可以了
yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
3)Install Docker Engine
安装docker引擎
yum install docker-ce docker-ce-cli containerd.io
弹出Installed size: 378 M
Is this ok [y/N]:
的时候,输入Y,继续安装
To install a specific version of Docker Engine, list the available versions in the repo, then select and install:
要安装特定的版本,我们先把现有的版本都查看一下
yum list docker-ce --showduplicates | sort -r
Last metadata expiration check: 0:05:13 ago on Sat 26 Feb 2022 04:30:49 PM CST.
Installed Packages
docker-ce.x86_64 3:20.10.9-3.el8 docker-ce-stable
docker-ce.x86_64 3:20.10.8-3.el8 docker-ce-stable
docker-ce.x86_64 3:20.10.7-3.el8 docker-ce-stable
docker-ce.x86_64 3:20.10.6-3.el8 docker-ce-stable
docker-ce.x86_64 3:20.10.5-3.el8 docker-ce-stable
docker-ce.x86_64 3:20.10.4-3.el8 docker-ce-stable
docker-ce.x86_64 3:20.10.3-3.el8 docker-ce-stable
docker-ce.x86_64 3:20.10.2-3.el8 docker-ce-stable
安装指定的版本:
yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io
我们选择其中一个版本来安装
yum -y install docker-ce.x86_64 docker-ce-cli-20.10.9-3.el8 containerd.io
Last metadata expiration check: 0:08:31 ago on Sat 26 Feb 2022 04:30:49 PM CST.
Package docker-ce-3:20.10.12-3.el8.x86_64 is already installed.
Package containerd.io-1.4.12-3.1.el8.x86_64 is already installed.
Dependencies resolved.
===============================================================================================================================
Package Architecture Version Repository Size
===============================================================================================================================
Downgrading:
docker-ce-cli x86_64 1:20.10.9-3.el8 docker-ce-stable 29 M
Transaction Summary
===============================================================================================================================
Downgrade 1 Package
Total download size: 29 M
Downloading Packages:
docker-ce-cli-20.10.9-3.el8.x86_64.rpm 1.4 MB/s | 29 MB 00:21
-------------------------------------------------------------------------------------------------------------------------------
Total 1.4 MB/s | 29 MB 00:21
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Downgrading : docker-ce-cli-1:20.10.9-3.el8.x86_64 1/2
Running scriptlet: docker-ce-cli-1:20.10.9-3.el8.x86_64 1/2
Cleanup : docker-ce-cli-1:20.10.12-3.el8.x86_64 2/2
Running scriptlet: docker-ce-cli-1:20.10.12-3.el8.x86_64 2/2
Verifying : docker-ce-cli-1:20.10.9-3.el8.x86_64 1/2
Verifying : docker-ce-cli-1:20.10.12-3.el8.x86_64 2/2
Downgraded:
docker-ce-cli-1:20.10.9-3.el8.x86_64
Complete!
4)Start Docker.
启动docker
[root@10-13 backup]# systemctl start docker
[root@10-13backup]#
[root@10- backup]# ps aux | grep docker
root 1601541 0.8 2.0 1368268 79388 ? Ssl 16:41 0:00 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
root 1601700 0.0 0.0 12108 972 pts/1 S+ 16:41 0:00 grep --color=auto docker
[root@10- backup]#
ps 命令可以看到,docker守护进程已经跑起来了
5)Verify that Docker Engine is installed correctly by running the hello-world image.
验证docker引擎是否安装成功
This command downloads a test image and runs it in a container. When the container runs, it prints a message and exits.
[root@10-14 backup]# docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
可以看到Hello from Docker!
说明docker引擎安装成功了