树莓派 docker服务启动失败

本文记录了在2021年劳动节后遇到的Docker服务崩溃问题,表现为Gitlab占用过高CPU资源,导致服务无法启动。解决步骤包括:检查docker服务状态,尝试重启服务,修改daemon.json配置文件,添加镜像源,重新加载配置并启动服务,如果仍无法解决则考虑卸载并重新安装Docker,并提供了一份docker.service配置文件作为参考。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前因: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

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值