docker安装完了以后服务启动不了Cannot connect to the Docker daemon at
docker安装完了以后服务启动不了Cannot connect to the Docker daemon at unix:///var/run/docker.sock.
centos7、ubuntu_21通过apt install docker安装docker后发现有的可以正常使用有的不能正常使用,当我启动docker时使用docker有关的命令都会报错,百度过,说什么重装docker啥的,我都试过,但是还是解决不了问题,下面我贴出问题集:
报错信息如下:
root@localhost:~# docker ps
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
root@localhost:~# docker -v
Docker version 20.10.0, build 7287ab3
root@localhost:~# systemctl start docker
Job for docker.service failed because the control process exited with error code.
See "systemctl status docker.service" and "journalctl -xe" for details.
root@localhost:~#
root@localhost:~#
root@localhost:~# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sat 2022-01-22 15:19:42 KST; 9s ago
TriggeredBy: ● docker.socket
Docs: https://docs.docker.com
Process: 32473 ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock (code=exited, status=1/FAILURE)
Main PID: 32473 (code=exited, status=1/FAILURE)
Jan 22 15:19:42 localhost systemd[1]: docker.service: Scheduled restart job, restart counter is at 3.
Jan 22 15:19:42 localhost systemd[1]: Stopped Docker Application Container Engine.
Jan 22 15:19:42 localhost systemd[1]: docker.service: Start request repeated too quickly.
Jan 22 15:19:42 localhost systemd[1]: docker.service: Failed with result 'exit-code'.
Jan 22 15:19:42 localhost systemd[1]: Failed to start Docker Application Container Engine.
最后解决问题方法是:
进入 /etc/docker 查看有没有daemon.json文件,如果没有就自己新建一个:
root@localhost:~# ll /etc/docker/daemon.json
root@localhost:~# nano /etc/docker/daemon.json
编辑daemon.json文件:
加入这段代码(或备份后只添加以下代码):
{
"registry-mirrors": ["https://registry.docker-cn.com"]
}
然后重启docker:systemctl restart docker.service
查看状态正常了 systemctl status docker.service
再使用docker命令时,就没有问题了
希望这个方法对你们有用
参考链接
https://www.cnblogs.com/huhyoung/p/9495956.html
http://www.docker.org.cn/thread/72.html