Debian系统下Docker服务无法通过systemctl启动的修复求助
Looks like your docker.service file got corrupted during the VM crash—right now it only has the environment variable line, missing all the required systemd service sections that tell systemd how to start/stop Docker. That's exactly why you're seeing those "Assignment outside of section" and "lacks ExecStart/ExecStop" errors.
Here's how to fix it step by step:
Backup the broken file first (just in case):
sudo cp /lib/systemd/system/docker.service /lib/systemd/system/docker.service.bakReplace the corrupted service file with a valid one
Open the file with your favorite editor (I'll use nano here for simplicity):sudo nano /lib/systemd/system/docker.servicePaste the following content (this matches the default Docker service config for Debian 9, plus your existing environment variable):
[Unit] Description=Docker Application Container Engine Documentation=https://docs.docker.com After=network-online.target firewalld.service containerd.service Wants=network-online.target Requires=containerd.service [Service] Type=notify ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock ExecReload=/bin/kill -s HUP $MAINPID TimeoutSec=0 RestartSec=2 Restart=always StartLimitBurst=3 StartLimitInterval=60s LimitNOFILE=infinity LimitNPROC=infinity LimitCORE=infinity TasksMax=infinity Delegate=yes KillMode=process Environment="GOOGLE_APPLICATION_CREDENTIALS=/etc/docker/key.json" [Install] WantedBy=multi-user.targetSave and exit: press
Ctrl+O, hit Enter, thenCtrl+X.Reload systemd and restart Docker
Tell systemd to pick up the new service config:sudo systemctl daemon-reloadNow start Docker via systemctl:
sudo systemctl start dockerVerify everything works
Check the service status to confirm it's running:sudo systemctl status dockerIf you want Docker to start automatically on boot, run:
sudo systemctl enable docker
This restores the full, valid systemd service structure while keeping your GOOGLE_APPLICATION_CREDENTIALS environment variable—systemd will now know exactly how to manage the Docker service again.
内容的提问来源于stack exchange,提问作者DarkLeafyGreen

