1 需要把yum 包更新到最新
yum update
2 安装需要的依赖包 yum-util提供yum-config-manager功能,另外两个是devicemapper驱动依赖的。
yum install -y yum-utils device-mapper-persistent-data lvm2
3 设置yum源
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror, langpacks
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
4 安装docker,出现输入的界面都输入y
yum install -y docker-ce
Retrieving key from https://download.docker.com/linux/centos/gpg
Importing GPG key 0x621E9F35:
Userid : "Docker Release (CE rpm)
Fingerprint: 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35
From : https://download.docker.com/linux/centos/gpg
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : 2:container-selinux-2.107-3.el7.noarch 1/4
Installing : containerd.io-1.2.13-3.1.el7.x86_64 2/4
Installing : 1:docker-ce-cli-19.03.8-3.el7.x86_64 3/4
Installing : 3:docker-ce-19.03.8-3.el7.x86_64 4/4
Verifying : containerd.io-1.2.13-3.1.el7.x86_64 1/4
Verifying : 2:container-selinux-2.107-3.el7.noarch 2/4
Verifying : 3:docker-ce-19.03.8-3.el7.x86_64 3/4
Verifying : 1:docker-ce-cli-19.03.8-3.el7.x86_64 4/4
Installed:
docker-ce.x86_64 3:19.03.8-3.el7
Dependency Installed:
container-selinux.noarch 2:2.107-3.el7 containerd.io.x86_64 0:1.2.13-3.1.el7 docker-ce-cli.x86_64 1:19.03.8-3.el7
Complete!
5 查看安装版本
docker -v
Docker version 19.03.8, build afacb8b
6 启动并加入开机启动
systemctl start docker
systemctl enable docker
7 查看active (running) 状态,说明安装成功
[root@localhost ~]# systemctl status docker
â— docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2020-04-14 06:07:54 PDT; 16s ago
Docs: https://docs.docker.com
Main PID: 52155 (dockerd)
CGroup: /system.slice/docker.service
└─52155 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
Apr 14 06:07:53 localhost.localdomain dockerd[52155]: time="2020-04-14T06:07:53.222629366-07:00" level=info msg="scheme \"unix\" not registered, fallback to default scheme" module=grpc
Apr 14 06:07:53 localhost.localdomain dockerd[52155]: time="2020-04-14T06:07:53.222650921-07:00" level=info msg="ccResolverWrapper: sending update to cc: {[{unix:///run/container...module=grpc
Apr 14 06:07:53 localhost.localdomain dockerd[52155]: time="2020-04-14T06:07:53.222662364-07:00" level=info msg="ClientConn switching balancer to \"pick_first\"" module=grpc
Apr 14 06:07:53 localhost.localdomain dockerd[52155]: time="2020-04-14T06:07:53.300026070-07:00" level=info msg="Loading containers: start."
Apr 14 06:07:53 localhost.localdomain dockerd[52155]: time="2020-04-14T06:07:53.782280147-07:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0....IP address"
Apr 14 06:07:54 localhost.localdomain dockerd[52155]: time="2020-04-14T06:07:54.264792895-07:00" level=info msg="Loading containers: done."
Apr 14 06:07:54 localhost.localdomain dockerd[52155]: time="2020-04-14T06:07:54.328307265-07:00" level=info msg="Docker daemon" commit=afacb8b graphdriver(s)=overlay2 version=19.03.8
Apr 14 06:07:54 localhost.localdomain dockerd[52155]: time="2020-04-14T06:07:54.328844251-07:00" level=info msg="Daemon has completed initialization"
Apr 14 06:07:54 localhost.localdomain dockerd[52155]: time="2020-04-14T06:07:54.488230695-07:00" level=info msg="API listen on /var/run/docker.sock"
Apr 14 06:07:54 localhost.localdomain systemd[1]: Started Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost ~]#