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

如题,使用docker时提示如下操作。可能是服务器重启而docker未重启造成。

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

可使用如下操作查看docker状态。

systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
     Docs: https://docs.docker.com

状态为:inactive,说明需要重启。

systemctl start docker
  • 如果重启正常

再次使用上上一步命令查看docker状态

systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
   Active: active (running) since Wed 2022-01-12 10:01:36 CST; 2min 33s ago
     Docs: https://docs.docker.com
 Main PID: 1646 (dockerd)
    Tasks: 9
   Memory: 163.1M
   CGroup: /system.slice/docker.service
           └─1646 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

此时,发现dockers已经正常运行。

  • 如果重启异常如下
systemctl start docker
Failed to start docker.service: The name org.freedesktop.PolicyKit1 was not provided by any .service files
See system logs and 'systemctl status docker.service' for details.

则需要去创建文件

sudo vi /etc/docker/daemon.json

内容如下

{
        "registry-mirrors": ["https://us6h4sfn.mirror.aliyuncs.com","http://hub-mirror.c.163.com","https://registry.docker-cn.com"] ,
  "data-root": "/usr/docker.images.data"
}

还有的人,需要包含(未验证)

"storage-driver": "devicemapper"

然后重启docker服务,并查询,发现启动成功了。

sudo systemctl restart docker

sudo systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
   Active: active (running) since Thu 2022-10-27 01:30:15 UTC; 10s ago
     Docs: https://docs.docker.com
  Process: 3057 ExecStartPre=/usr/libexec/docker/docker-setup-runtimes.sh (code=exited, status=0/SUCCESS)
  Process: 3055 ExecStartPre=/bin/mkdir -p /run/docker (code=exited, status=0/SUCCESS)
 Main PID: 3059 (dockerd)
    Tasks: 8
   Memory: 94.0M
   CGroup: /system.slice/docker.service
           └─3059 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --default-ulimit nofile=32768:65536

附录:

如果docker未安装,可先使用如下命令安装docker。(适用于centos)

sudo yum install docker

参见:

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?_凌风少年z-CSDN博客

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值