ssh登录服务器:
[root@okqvd ~]# which docker
/usr/bin/which: no docker in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
[root@okqvd ~]# yum install docker
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
No package docker available.
Error: Nothing to do
[root@okqvd ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Loaded plugins: langpacks, product-id, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
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
[root@okqvd ~]# yum install docker-ce
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
docker-ce-stable | 3.5 kB 00:00:00
(1/2): docker-ce-stable/x86_64/updateinfo | 55 B 00:00:02
(2/2): docker-ce-stable/x86_64/primary_db | 28 kB 00:00:02
Resolving Dependencies
--> Running transaction check
---> Package docker-ce.x86_64 3:18.09.6-3.el7 will be installed
--> Processing Dependency: container-selinux >= 2.9 for package: 3:docker-ce-18.09.6-3.el7.x86_64
--> Processing Dependency: containerd.io >= 1.2.2-3 for package: 3:docker-ce-18.09.6-3.el7.x86_64
--> Processing Dependency: docker-ce-cli for package: 3:docker-ce-18.09.6-3.el7.x86_64
--> Running transaction check
---> Package containerd.io.x86_64 0:1.2.5-3.1.el7 will be installed
---> Package docker-ce.x86_64 3:18.09.6-3.el7 will be installed
--> Processing Dependency: container-selinux >= 2.9 for package: 3:docker-ce-18.09.6-3.el7.x86_64
---> Package docker-ce-cli.x86_64 1:18.09.6-3.el7 will be installed
--> Finished Dependency Resolution
Error: Package: 3:docker-ce-18.09.6-3.el7.x86_64 (docker-ce-stable)
Requires: container-selinux >= 2.9
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest
如何解决报错?
安装更高版本的container-selinux即可: 更多版本参考http://mirror.centos.org/centos/7/extras/x86_64/Packages/
[root@okqvd ~]# yum install -y http://mirror.centos.org/centos/7/extras/x86_64/Packages/container-selinux-2.95-2.el7_6.noarch.rpm
再尝试安装docker-ce,即可:
[root@okqvd ~]# yum install docker-ce
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Resolving Dependencies
--> Running transaction check
---> Package docker-ce.x86_64 3:18.09.6-3.el7 will be installed
--> Processing Dependency: containerd.io >= 1.2.2-3 for package: 3:docker-ce-18.09.6-3.el7.x86_64
--> Processing Dependency: docker-ce-cli for package: 3:docker-ce-18.09.6-3.el7.x86_64
--> Running transaction check
---> Package containerd.io.x86_64 0:1.2.5-3.1.el7 will be installed
---> Package docker-ce-cli.x86_64 1:18.09.6-3.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=================================================================================================================================================================================================================
Package Arch Version Repository Size
=================================================================================================================================================================================================================
Installing:
docker-ce x86_64 3:18.09.6-3.el7 docker-ce-stable 19 M
Installing for dependencies:
containerd.io x86_64 1.2.5-3.1.el7 docker-ce-stable 22 M
docker-ce-cli x86_64 1:18.09.6-3.el7 docker-ce-stable 14 M
Transaction Summary
=================================================================================================================================================================================================================
Install 1 Package (+2 Dependent packages)
Total download size: 55 M
Installed size: 236 M
Is this ok [y/d/N]: y
Downloading packages:
warning: /var/cache/yum/x86_64/7Server/docker-ce-stable/packages/docker-ce-18.09.6-3.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY ] 876 kB/s | 37 MB 00:00:21 ETA
Public key for docker-ce-18.09.6-3.el7.x86_64.rpm is not installed
(1/3): docker-ce-18.09.6-3.el7.x86_64.rpm | 19 MB 00:00:43
(2/3): containerd.io-1.2.5-3.1.el7.x86_64.rpm | 22 MB 00:00:52
(3/3): docker-ce-cli-18.09.6-3.el7.x86_64.rpm | 14 MB 00:00:38
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 686 kB/s | 55 MB 00:01:21
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
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : 1:docker-ce-cli-18.09.6-3.el7.x86_64 1/3
Installing : containerd.io-1.2.5-3.1.el7.x86_64 2/3
Installing : 3:docker-ce-18.09.6-3.el7.x86_64 3/3
Verifying : containerd.io-1.2.5-3.1.el7.x86_64 1/3
Verifying : 3:docker-ce-18.09.6-3.el7.x86_64 2/3
Verifying : 1:docker-ce-cli-18.09.6-3.el7.x86_64 3/3
Installed:
docker-ce.x86_64 3:18.09.6-3.el7
Dependency Installed:
containerd.io.x86_64 0:1.2.5-3.1.el7 docker-ce-cli.x86_64 1:18.09.6-3.el7
Complete!
[root@okqvd ~]# which docker
/usr/bin/docker
[root@okqvd ~]# docker --version
Docker version 18.09.6, build 481bc77156
另一种安装方式:
# 添加docker yum仓库 用于centos 7
$ tee /etc/yum.repos.d/docker.repo << EOF
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF
# 安装docker
$ yum update -y && yum install -y docker-engine
# 设置代理
$ mkdir -p /etc/systemd/system/docker.service.d
touch "/etc/systemd/system/docker.service.d/http-proxy.conf"
tee > "/etc/systemd/system/docker.service.d/http-proxy.conf" << DOCKER_PROXY
[Service]
Environment="HTTP_PROXY=http://10.xxx.xx.xx:8080"
DOCKER_PROXY
# 更新daemon并启动docker
$ systemctl daemon-reload && systemctl restart docker
如果已经安装了docker,使用下面方式卸载删除:
$ yum remove docker docker-common docker-selinux docker-engine