树莓派 docker服务启动失败

Posted 久天.

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了树莓派 docker服务启动失败相关的知识,希望对你有一定的参考价值。

前因:2021年劳动节后,发现好几个线上docker起的服务挂掉了,htop查看发现是Gitlab太耗,占用了大量CPU,导致docker服务崩掉了,但是在多次重启docker服务都起不来,相关报错和解决方案如下

相关报错

1. 查看docker服务状态

systemctl status docker

2. 查看docker 所有容器

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

解决方案

在/etc/docker/目录下创建daemon.json,添加如下内容:

{
 "registry-mirrors": ["https://registry.docker-cn.com"]
}

加载新的 unit 配置文件

sudo systemctl reload-daemon 

运行以下命令进行重启

sudo systemctl  start  docker

如若还不行,可尝试重启树莓派

sudo reboot

 

兜底方案

删除docker服务

sudo yum erase -y docker-client.x86_64
sudo yum erase -y docker-common.x86_64
sudo yum remove docker \\
docker-common \\
container-selinux \\
docker-selinux \\
docker-engine

安装

curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

 

附加 docker.service 配置文件

cat /lib/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service containerd.service
Wants=network-online.target
Requires=docker.socket containerd.service

[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ExecStart=
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always

# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3

# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s

# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity

# Comment TasksMax if your systemd version does not support it.
# Only systemd 226 and above support this option.
TasksMax=infinity

# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes

# kill only the docker process, not all processes in the cgroup
KillMode=process
OOMScoreAdjust=-500

[Install]
WantedBy=multi-user.target

参考

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

Docker can't connect to docker daemon

以上是关于树莓派 docker服务启动失败的主要内容,如果未能解决你的问题,请参考以下文章

利用树莓派搭建个人服务器

树莓派应用Docker

树莓派安装docker,并在PC端监控,启动swarm集群

树莓派4B安装 docker 和 docker-compose

树莓派docker安装nginx+php备忘录

树莓派 python 如何将本地文件上传到指定的服务器页面上