Skip to main content

Docker Engine (Part 10)

Troubleshooting the Docker Daemon

Updated 5 min readMarkdown
Part of seriesDemystifying Docker

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_HOST environment 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 (requires DOCKER_TLS_VERIFY=1 and 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) or failed: 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:

  1. Invalid JSON or Directive Conflicts in /etc/docker/daemon.json: A trailing comma, syntax error, or duplicate flag (such as defining "hosts" in daemon.json when -H fd:// is already passed in docker.service) will immediately prevent dockerd from starting.
  2. Storage Driver or Disk Errors: Failures initializing overlay2 or 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

Cannot connect to the Docker daemon

sudo systemctl status docker

Start service (systemctl start docker) or fix $DOCKER_HOST

Service fails on startup

sudo journalctl -u docker.service -n 50

Fix syntax or flag conflicts in /etc/docker/daemon.json

No space left on device

df -h /var/lib/docker & docker system df

Free disk space with docker container prune & docker image prune

Need verbose runtime logs

Set "debug": true in /etc/docker/daemon.json

Reload live with sudo systemctl reload docker or kill -SIGHUP $(pidof dockerd)

No comments yet. Be the first to comment.