Project scene:
Tip: When creating k8s with rancher, one of the servers reported Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Problem Description:
So I went to the server and checked the reason. Whether it was docker run helloworld or docker info, it reported Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Then check the log
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.
Look at the detailed log
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.
Cause Analysis:
After repeated tossing, reinstalling, using different mirror sources, and using check-config.sh to check the configuration of the docker environment , according to the results of its scan, Baidu and Google solved some of the problems!
./check-config.sh
其中出现 (RHEL7/CentOS7: User namespaces disabled; add 'user_namespace.enable=1' to boot command line)
solution:
groupadd docker
usermod -aG docker $(whoami)
service docker start
Solutions to other problems:
1. Run yum list installed | grep docker command, prompting that Repository epel is listed more than once in the configuration
solution:
zip centos7-repo.zip /etc/yum.repos.d/*
Back up the original configuration items and be prepared!
Universal solution:
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. In centos7, docker info reports an error docker bridge-nf-call-iptables is disabled solution
solution:
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. Check which rpm docker has and kill it!
yum list installed | grep docker
yum -y remove docker-ce-cli.x86_64
yum -y remove containerd.io.x86_64
4. Back up /etc/docker/daemon.json. I have used many mirrors and tested a lot, but Ali is more reliable
cat >/etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors":["https://jnxt8d8b.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload && systemctl restart docker
5. At this time, docker info
systemctl status docker
docker info
solution:
Tip: docker reports an error Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon?
what can we do about it?
Encountered a bug, an occupational disease, and still refuse to let it go... This is a mistake, eat something, have a cup of coffee... I guess I'm crazy...
Take a look again
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. Remove --registry-mirror=http://3cda3ca9.m.daocloud.io
vim /etc/systemd/system/docker.service
I don’t know which blog to watch, I added it! After removing
[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
solution:
echo 'export DOCKER_HOST=tcp://0.0.0.0:2375' >> /etc/profile
source /etc/profile
systemctl daemon-reload && systemctl restart docker
Friendly link: https://www.cnblogs.com/weiyiming007/p/10168733.html
Finally, docker info, solve the problem!
docker info
systemctl status docker