專案場景:
提示:在用rancher創建k8s的時候,其中一臺服務器,報Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
問題描述:
于是到該臺服務器,查看原因,無論是docker run helloworld ,還是docker info,都報Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
于是查看日志
systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/etc/systemd/system/docker.service; enabled; vendor preset: disabled)
Active: activating (auto-restart) (Result: exit-code) since 四 2020-09-17 17:18:16 CST; 1s ago
Docs: http://docs.docker.io
Process: 6430 ExecStartPost=/sbin/iptables -I FORWARD -s 0.0.0.0/0 -j ACCEPT (code=exited, status=0/SUCCESS)
Process: 6429 ExecStart=/opt/kube/bin/dockerd --registry-mirror=http://3cda3ca9.m.daocloud.io -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375 (code=exited, status=1/FAILURE)
Main PID: 6429 (code=exited, status=1/FAILURE)
9月 17 17:18:16 cdh2-4 systemd[1]: Unit docker.service entered failed state.
9月 17 17:18:16 cdh2-4 systemd[1]: docker.service failed.
再看詳細日志
journalctl -u docker.service
9月 08 21:12:32 cdh2-4 systemd[1]: Starting Docker Application Container Engine...
9月 08 21:12:32 cdh2-4 dockerd[17900]: time="2020-09-08T21:12:32.921547656+08:00" level=warning msg="could not change group /var/run/docker.sock to docker: group docker not found"
9月 08 21:12:32 cdh2-4 dockerd[17900]: time="2020-09-08T21:12:32.953783378+08:00" level=warning msg="failed to load plugin io.containerd.snapshotter.v1.btrfs" error="path /var/lib/docker/contain
9月 08 21:12:32 cdh2-4 dockerd[17900]: time="2020-09-08T21:12:32.956534309+08:00" level=warning msg="failed to load plugin io.containerd.snapshotter.v1.aufs" error="modprobe aufs failed: "modpro
9月 08 21:12:32 cdh2-4 dockerd[17900]: time="2020-09-08T21:12:32.957510869+08:00" level=warning msg="could not use snapshotter zfs in metadata plugin" error="path /var/lib/docker/containerd/daem
9月 08 21:12:32 cdh2-4 dockerd[17900]: time="2020-09-08T21:12:32.957525885+08:00" level=warning msg="could not use snapshotter btrfs in metadata plugin" error="path /var/lib/docker/containerd/da
9月 08 21:12:32 cdh2-4 dockerd[17900]: time="2020-09-08T21:12:32.957533745+08:00" level=warning msg="could not use snapshotter aufs in metadata plugin" error="modprobe aufs failed: "modprobe: FA
9月 08 21:12:33 cdh2-4 systemd[1]: Started Docker Application Container Engine.
原因分析:
經過反復折騰,重裝,采用不同的鏡像源,同時采用檢查docker環境的配置check-config.sh,根據其掃描的結果,百度和google,解決一部分問題!
./check-config.sh
其中出現 (RHEL7/CentOS7: User namespaces disabled; add 'user_namespace.enable=1' to boot command line)
解決方案:
groupadd docker
usermod -aG docker $(whoami)
service docker start
其他問題的解決:
1,運行yum list installed | grep docker命令,提示Repository epel is listed more than once in the configuration
解決方案:
zip centos7-repo.zip /etc/yum.repos.d/*
對原來的配置項進行備份,有備無患!
萬能解決方案:
cd /etc/yum.repos.d/
wget http://mirrors.aliyun.com/repo/Centos-7.repo
sed -i 's/^.*aliyuncs*/#&/g' /etc/yum.repos.d/CentOS-Base.repo
wget https://mirrors.aliyun.com/repo/epel-7.repo
2,在centos7 中docker info報錯docker bridge-nf-call-iptables is disabled解決辦法
解決方案:
cat > /etc/sysctl.d/docker.conf <<-'EOF'
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-arptables = 1
EOF
sysctl --system
sysctl -p
3,查看docker有哪些rpm,干掉!
yum list installed | grep docker
yum -y remove docker-ce-cli.x86_64
yum -y remove containerd.io.x86_64
4,備份/etc/docker/daemon.json,用過很多家的鏡像,測驗了很多,還是阿里比較靠譜
cat >/etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors":["https://jnxt8d8b.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload && systemctl restart docker
5,這時候,docker info一下
systemctl status docker
docker info

解決方案:
提示:docker報錯Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon?
該怎么辦呢?
遇見bug,職業病,還是不肯放過它……這是錯誤,吃點東西,喝杯咖啡……估計走火入魔了……
再來看看
systemctl status docker
docker.service - Docker Application Container Engine
Loaded: loaded (/etc/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: activating (auto-restart) (Result: exit-code) since 四 2020-09-17 17:49:59 CST; 466ms ago
Docs: http://docs.docker.io
Process: 15193 ExecStartPost=/sbin/iptables -I FORWARD -s 0.0.0.0/0 -j ACCEPT (code=exited, status=0/SUCCESS)
Process: 15192 ExecStart=/opt/kube/bin/dockerd --registry-mirror=http://3cda3ca9.m.daocloud.io -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375 (code=exited, status=1/FAILURE)
Main PID: 15192 (code=exited, status=1/FAILURE)
1,把--registry-mirror=http://3cda3ca9.m.daocloud.io這個去掉
vim /etc/systemd/system/docker.service

不知道看哪個博客,手賤加上的!去掉以后
[Unit]
Description=Docker Application Container Engine
Documentation=http://docs.docker.io
[Service]
Environment="PATH=/opt/kube/bin:/bin:/sbin:/usr/bin:/usr/sbin"
ExecStart=/opt/kube/bin/dockerd -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375
ExecStartPost=/sbin/iptables -I FORWARD -s 0.0.0.0/0 -j ACCEPT
ExecReload=/bin/kill -s HUP $MAINPID
Restart=always
RestartSec=5
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
Delegate=yes
KillMode=process
[Install]
WantedBy=multi-user.target
2,Cannot connect to the Docker daemon at tcp://0.0.0.0:2375. Is the docker daemon
解決方案:
echo 'export DOCKER_HOST=tcp://0.0.0.0:2375' >> /etc/profile
source /etc/profile
systemctl daemon-reload && systemctl restart docker
友情鏈接:https://www.cnblogs.com/weiyiming007/p/10168733.html
最后docker info一下,解決問題!
docker info

systemctl status docker

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/74004.html
標籤:其他
