Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

今天打开centos7,由于没设置开机自启,当我启动docker时,发现与docker有关的命令都会报错,百度过,说什么重装docker啥的,我都试过,但是还是解决不了问题,下面我贴出问题集:

1. 例如我查看版本信息
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?_第1张图片
2.重启容器
在这里插入图片描述
3. systemctl status docker 查看docker状态也发现错误:

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?_第2张图片
最后解决问题方法是:
进入 /etc/docker,没有daemon.json文件就自己新建一个:

cd /etc/docker

在这里插入图片描述
编辑daemon.json文件:
加入这段代码:

{
 "registry-mirrors": ["https://registry.docker-cn.com"]
}

在这里插入图片描述
然后重启docker:

systemctl restart docker.service

再使用docker命令时,就没有问题了
希望这个方法对你们有用
最后,我是得益于这位博主的文章来写的,感谢~
https://www.cnblogs.com/huhyoung/p/9495956.html

各位朋友还是设置docker开机自启吧

你可能感兴趣的:(CentOS7,docker,centos,linux)