Docker Engine (Part 10)
Troubleshooting the Docker Daemon
Few errors stop a deployment workflow faster than seeing:
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
When this happens—or when Docker containers fail to start unexpectedly—having a structured troubleshooting checklist saves you from blindly restarting servers. In this guide, we will walk through diagnosing Docker daemon connectivity errors, inspecting service logs, reclaiming exhausted disk space, and dynamically toggling Debug Mode (debug: true) without interrupting running containers.
1. Check Remote Connection Settings (DOCKER_HOST)
If you are running Docker CLI commands from a remote client (such as your laptop or a CI/CD runner) targeting a remote Docker host, verify your environment configuration first:
- Confirm the
DOCKER_HOSTenvironment variable points to the right IP address and port:
echo $DOCKER_HOST
- Verify you are using the matching port for your TLS setup:
2375— Unencrypted TCP traffic (local/private networks only).2376— Encrypted TLS traffic (requiresDOCKER_TLS_VERIFY=1and valid client certificates).
- Test network reachability to the host port (
nc -zv <host_ip> 2376).
If you are working locally on the Docker host—or your remote network settings are verified—move on to checking the daemon service itself.
2. Check the Docker Service Status & Systemd Logs
On Linux systems, dockerd runs as a background service managed by systemd.
Step 1: Check Service State
Run systemctl status on the Docker host:
sudo systemctl status docker
active (running): The daemon is up (if local CLI commands still fail, check if your user lacks permissions on/var/run/docker.sock).inactive (dead)orfailed: The daemon stopped or crashed during startup.
Step 2: Inspect Daemon Startup Logs (journalctl)
To find out why the service failed to start, query systemd's journal logs for the docker unit:
sudo journalctl -u docker.service -n 50 --no-pager
Look for two of the most common root causes in these logs:
- Invalid JSON or Directive Conflicts in
/etc/docker/daemon.json: A trailing comma, syntax error, or duplicate flag (such as defining"hosts"indaemon.jsonwhen-H fd://is already passed indocker.service) will immediately preventdockerdfrom starting. - Storage Driver or Disk Errors: Failures initializing
overlay2or writing metadata to/var/lib/docker.
3. Check Disk Space & Reclaim Storage (prune)
Docker stores all images, container layers, build caches, and volumes inside /var/lib/docker. When heavy image pulls or large container logs fill up the underlying partition, the Docker daemon can crash or refuse to start new containers.
Check Available Disk Space
Verify free space on the filesystem hosting /var/lib/docker:
df -h /var/lib/docker
Reclaim Unused Docker Storage
Inspect how much disk space Docker objects are consuming:
docker system df
Clean up unused resources safely:
# Remove all stopped containers
docker container prune
# Remove dangling/unused images (add -a to remove all images not tied to a container)
docker image prune
# Or reclaim unused containers, networks, and dangling images in one step
docker system prune
4. Enabling Docker Daemon Debug Mode Live
By default, Docker logs only high-level lifecycle events (such as container creation or exit messages) to /var/log/messages or /var/log/syslog and journalctl. When diagnosing subtle networking, storage, or runtime issues, you need verbose debug logs.
Step 1: Verify Current Debug Mode
Check whether debug mode is currently enabled:
docker system info | grep -i "debug mode"
# Output: Debug Mode: false
Step 2: Set "debug": true in /etc/docker/daemon.json
Open /etc/docker/daemon.json (create it if it doesn't exist) and set "debug" to true:
JSON
{
"debug": true
}
Step 3: Reload the Configuration Without Stopping Containers
Instead of running systemctl restart docker (which stops running containers unless Live Restore is enabled), reload the configuration cleanly:
Option A — Using systemctl reload:
sudo systemctl reload docker
Option B — Sending SIGHUP directly to the dockerd PID:
Bash
sudo kill -SIGHUP $(pidof dockerd)
Step 4: Verify & Inspect Detailed Logs
Confirm that debug mode is now active:
Bash
docker system info | grep -i "debug mode"
# Output: Debug Mode: true
Now, when you run a container (docker container run --rm hello-world), inspect your system logs (sudo tail -f /var/log/messages on RHEL/CentOS or sudo journalctl -u docker.service -f on Ubuntu) to see step-by-step level=debug entries detailing image layer mounts, network sandbox creation, and containerd calls.
(Note: Once you finish troubleshooting, set "debug": false in /etc/docker/daemon.json and send SIGHUP again—debug logging generates high log volume and can fill up /var/log if left on permanently.)
Quick Troubleshooting Workflow Summary
Symptom | Diagnostic Command | Fix |
|
| Start service ( |
Service fails on startup |
| Fix syntax or flag conflicts in |
No space left on device |
| Free disk space with |
Need verbose runtime logs | Set | Reload live with |
Comments
Join the discussionNo comments yet. Be the first to comment.