Debian Stretch 9服务器Docker守护进程连接失败求助
Hey there, let's work through these Docker and command-line issues together—you've got a couple of overlapping problems here, so we'll break them down step by step.
First: Fix Missing shutdown/service Commands
The "command not found" errors for shutdown and service are almost always related to your user's PATH environment variable not including system administrative directories, or not running commands as root. Try these fixes:
- Switch to the root user first (this will load the full admin PATH):
Now you should be able to runsu - rootservice docker stoporshutdown -h nowwithout issues. - If you don't want to switch to root, use the absolute paths for these commands:
# Stop Docker /usr/sbin/service docker stop # Shutdown the server /sbin/shutdown -h now
Next: Resolve Docker Daemon Connection Failure
The "Cannot connect to the Docker daemon" error, paired with the pidfile warning, means Docker's daemon isn't running properly (or has leftover invalid state). Let's clean up and restart:
Check for leftover Docker processes
Even though the stop command said process 13454 didn't exist, double-check for any lingering Docker-related processes:ps aux | grep dockerIf you see any processes listed (other than the grep itself), kill them with:
kill -9 <PROCESS_ID>Replace
<PROCESS_ID>with the actual ID from the output.Clean up invalid state files
The pidfile and socket file might be corrupted or leftover from a crashed daemon:# Remove the invalid pidfile rm -f /var/run/docker-ssd.pid # Remove the old Docker socket file rm -f /var/run/docker.sockRestart the Docker service
Use the absolute path (or run as root) to start Docker:/usr/sbin/service docker startIf your system uses systemd (Debian Stretch defaults to this), you can also try:
systemctl start docker.serviceCheck Docker daemon logs for root causes
If Docker still won't start, the logs will tell you exactly what's wrong (e.g., config syntax errors, permission issues, missing dependencies):# Check syslog for Docker messages tail -n 50 /var/log/syslog | grep docker # Or use journalctl if systemd is enabled journalctl -u docker.service -n 50
Additional Troubleshooting Steps
If the above doesn't work, try these deeper checks:
- Validate Docker configuration: The
/etc/docker/daemon.jsonfile (if it exists) might have syntax errors. Check it with:
Ensure all brackets and commas are properly formatted—even a missing comma can crash the daemon.cat /etc/docker/daemon.json - Fix Docker socket permissions: After starting Docker, verify the socket has the right permissions:
It should be owned byls -l /var/run/docker.sockroot:docker. If not, fix it with:
Log out and back in for the group change to take effect.chown root:docker /var/run/docker.sock # Add your user to the docker group to avoid needing root for docker commands usermod -aG docker <YOUR_USERNAME> - Reinstall Docker: If all else fails, reinstall Docker to fix any corrupted dependencies or binaries. First back up your containers/images if needed, then run:
apt-get remove --purge docker-ce docker-ce-cli containerd.io apt-get install docker-ce=18.03.1~ce-0~debian-stretch docker-ce-cli=18.03.1~ce-0~debian-stretch containerd.io
内容的提问来源于stack exchange,提问作者Reda Vanclyce Benslal

