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

本文记录了在CentOS服务器上安装并启动Docker过程中遇到的连接失败问题及其解决方法。通过运行特定命令重启Docker服务解决了连接问题,并通过测试hello-world镜像验证了Docker的正确安装。


docker报错

新弄了个服务器,使用xshell7版本,进行了如下安装并启动docker的操作:

# 先卸载旧的docker版本
yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

# 安装工具包
yum install -y yum-utils

# 设置仓库
yum-config-manager \
    --add-repo \
    http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo # 这个是阿里云镜像,用这个
    
# 更新yum缓存
yum makecache fast

# 安装docker
yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin

# 启动docker
systemctl start docker
# 查看docker版本信息
docker version

此时,docker安装成功并启动,显示信息如下:

[root@VM-4-8-centos /]# docker version
Client: Docker Engine - Community
 Version:           20.10.18
 API version:       1.41
 Go version:        go1.18.6
 Git commit:        b40c2f6
 Built:             Thu Sep  8 23:14:08 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

报错内容为:

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


错误排查与解决

按照报错内容提示,说明少运行了daemon,于是百度运行命令,然后运行:

[root@VM-4-8-centos /]# systemctl daemon-reload
[root@VM-4-8-centos /]# systemctl restart docker.service

再重新查看,没有报错了:

在这里插入图片描述


检查测试

最简单的方法就是跑一遍hello-world镜像进行测试:

[root@VM-4-8-centos /]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:62af9efd515a25f84961b70f973a798d2eca956b1b2b026d0a4a63a3b0b6a3f2
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

ok,没问题了。


参考文档

  • https://blog.csdn.net/qq_42114918/article/details/81840335
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值