【亲测有效】Centos安装完成docker后启动docker报错docker: unrecognized service的两种解决方案

末鹿安然 提交于 2021-02-17 22:39:59

今天在学习Docker的时候

使用yum install docker安装完后启动不了,报错如下:

[root@Sakura ~]# service docker start 
docker: unrecognized service

一直停留在以上步骤,如果有遇到和我一样类似问题的小伙伴可以按照如下方法进行安装,即可安装成功~~

方法一:

先移除docker

[root@Sakura ~]# yum remove docker

再移除docker-selinux(如果你之前有安装过的话)

[root@Sakura ~]# yum remove docker-selinux

然后修改文件

[root@Sakura ~]# vi /etc/yum.repos.d/docker.repo

直接填入如下内容:

[dockerrepo]

name=Docker Repository

baseurl=https://yum.dockerproject.org/repo/main/centos/$releasever/

enabled=1

gpgcheck=1

gpgkey=https://yum.dockerproject.org/gpg

然后启动安装:

[root@Sakura ~]# yum install docker-engine

作为依赖被安装: docker-engine-selinux.noarch 0:1.10.2-1.el7.centos

然后启动docker服务:

[root@Sakura ~]# service docker start

返回如下状态码:

Starting cgconfig service:                                 [  OK  ]
Starting docker:                                           [  OK  ]

即可完美的使docker启动成功!!!

方法二:

直接用这条命令安装

[root@Sakura ~]# curl -fsSL https://get.docker.com/ | sh + sh -c 'sleep 3; yum -y -q install docker-engine'

可能会有以下提示信息,我们不需要去管:

警告:/var/cache/yum/x86_64/7/docker-main-repo/packages/docker-engine-selinux-1.10.2-1.el7.centos.noarch.rpm: 头V4 RSA/SHA512 Signature, 密钥 ID 2c52609d: NOKEY docker-engine-selinux-1.10.2-1.el7.centos.noarch.rpm 的公钥尚未安装 导入 GPG key 0x2C52609D: 用户ID : "Docker Release Tool (releasedocker) " 指纹 : 5811 8e89 f3a9 1289 7c07 0adb f762 2157 2c52 609d 来自 : https://yum.dockerproject.org/gpg setsebool: SELinux is disabled. + sh -c 'docker version' Client: Version: 1.10.2 API version: 1.22 Go version: go1.5.3 Git commit: c3959b1 Built: Mon Feb 22 16:16:33 2016 OS/Arch: linux/amd64 Cannot connect to the Docker daemon. Is the docker daemon running on this host? If you would like to use Docker as a non-root user, you should now consider adding your user to the "docker" group with something like: sudo usermod -aG docker your-user Remember that you will have to log out and back in for this to take effect!

然后直接启动就好了~~~

[root@Sakura ~]# service docker start Redirecting to /bin/systemctl start docker.service

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!