164人参与 • 2024-07-31 • Unix
最近遇到一台服务器重启后docker.service无法启动,记录解决过程。
1.执行docker ps
后,终端报错如下:
cannot connect to the docker daemon at unix:///var/run/docker.sock. is the docker daemon running?
2.执行systemctl status docker
查看详细信息如下:
不看不知道,一看吓一跳,好家伙,这台服务器上这两个文件都不翼而飞,于是从另一台docker功能正常的服务器拷贝上述两个文件到本机,由于docker安装时未修改默认配置,所以两个文件均未修改.
执行vim /lib/systemd/system/docker.service
,添加以下内容:
[unit]
description=docker application container engine
documentation=https://docs.docker.com
after=network-online.target docker.socket firewalld.service containerd.service time-set.target
wants=network-online.target containerd.service
requires=docker.socket
[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
execreload=/bin/kill -s hup $mainpid
timeoutstartsec=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
执行vim /lib/systemd/system/docker.socket
,添加以下内容:
vim /lib/systemd/system/docker.socket
[unit]
description=docker socket for the api
[socket]
# if /var/run is not implemented as a symlink to /run, you may need to
# specify listenstream=/var/run/docker.sock instead.
listenstream=/run/docker.sock
socketmode=0660
socketuser=root
socketgroup=docker
[install]
wantedby=sockets.target
systemctl daemon-reload
systemctl restart docker
# 验证是否修复
docker ps
# 相同报错
cannot connect to the docker daemon at unix:///var/run/docker.sock. is the docker daemon running?
执行以上命令重启docker后,发现报错还在,执行journalctl -u docker.service -f
查看docker服务详细信息,终端输出如下:
执行命令which containerd
, 发现服务器未安装containerd,执行以下命令安装
## 安装containerd
apt-get install containerd
## 再次查看
which containerd
## 输出如下
/usr/bin/containerd
docker重启后,执行docker ps
,此时docker已经可以正常使用:
使用过程中发现docker命令的tab键命令补全功能失效,在网上找到了解决方式:
## 1.下载自动补全脚本:
curl -o /etc/bash_completion.d/docker https://raw.githubusercontent.com/docker/cli/master/contrib/completion/bash/docker
## 2.重新加载bash配置:
source /etc/bash_completion.d/docker
您想发表意见!!点此发布评论
版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。
发表评论