安装之前,卸载旧版本
较旧的 Docker 版本称为 docker 或 docker-engine 。如果已安装这些程序,请卸载它们以及相关的依赖项。
[root@centos7 ~]# yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
安装 Docker Engine-Community
安装所需的软件包
[root@centos7 ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
yum-utils 提供了 yum-config-manager ,并且 device mapper 存储驱动程序需要 device-mapper-persistent-data 和 lvm2。
设置yum源(选择其中一个即可)
官方源(比较慢)
[root@centos7 ~]# yum-config-manager --add-repo http://download.docker.com/linux/centos/docker-ce.repo
阿里源
[root@centos7 ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
清华大学源
[root@centos7 ~]# yum-config-manager --add-repo https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo
可以查看所有仓库中所有docker版本,并选择特定版本安装
[root@centos7 ~]# yum list docker-ce --showduplicates | sort -r
安装
可以选择特定的版本安装,yum install docker-ce-版本号,我选的是docker-ce-20.10.1,如下
[root@centos7 ~]# yum install docker-ce-20.10.1
也可以不选版本号,直接安装:
[root@centos7 ~]# yum install docker-ce docker-ce-cli containerd.io
启动 docker:
[root@centos7 ~]# systemctl start docker
安装完成后,查看安装的docker版本
[root@centos7 ~]# docker version
Client: Docker Engine - Community
Version: 20.10.1
API version: 1.41
Go version: go1.13.15
Git commit: 831ebea
Built: Tue Dec 15 04:37:17 2020
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.1
API version: 1.41 (minimum version 1.12)
Go version: go1.13.15
Git commit: f001486
Built: Tue Dec 15 04:35:42 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.3
GitCommit: 269548fa27e0089a8b8278fc4fc781d7f65a939b
runc:
Version: 1.0.0-rc92
GitCommit: ff819c7e9184c13b7c2607fe6c30ae19403a7aff
docker-init:
Version: 0.19.0
GitCommit: de40ad0
设为开机自启动:
[root@centos7 ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
运行 hello-world 镜像来验证是否正确安装了 Docker Engine-Community 。
[root@centos7 ~]# 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/
[root@centos7 ~]#
成功安装。
以上。
同步发布至:https://www.toutiao.com/i6914088146883838467/
转载请附本文出处。