docker.service:服务缺少 ExecStart= 和 ExecStop= 设置。拒绝

时间:2020-12-19 12:25:39

标签: docker systemctl

我的虚拟机因为内存不足而崩溃。重新启动机器后,docker 没有运行:

systemctl status docker
● docker.service
   Loaded: error (Reason: Invalid argument)
   Active: inactive (dead)
Dec 19 08:18:21 my-vm-single-instance systemd[1]: [/lib/systemd/system/docker.service:1] Assignment outside of section. Ignoring.
Dec 19 08:18:21 my-vm-single-instance systemd[1]: docker.service: Service lacks both ExecStart= and ExecStop= setting. Refusing.

我使用官方文档安装了 docker:https://docs.docker.com/engine/install/debian/

VM 正在运行:

Debian GNU/Linux 9 (stretch)
Docker version 19.03.14, build 5eb3275d40
docker-compose version 1.25.4, build 8d51620a

我使用 docker 重新启动并运行

dockerd

但是我想通过 systemctl 让它再次运行。

/lib/systemd/system/docker.service 的内容是:

Environment="GOOGLE_APPLICATION_CREDENTIALS=/etc/docker/key.json"

任何想法如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

如果 docker.service 只包含一行,因为它提到的是假的。 正如它所说

docker.service: Service lacks both ExecStart= and ExecStop= setting. Refusing.

至少缺少执行脚本。

这是一个示例服务文件:

[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
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

这是我的默认服务文件。安装后我从未修改过。