This error means Docker’s internal communication layer, specifically the API, received an incomplete or malformed JSON payload from a Docker client (like your CLI or a Docker Compose command) when it was expecting a complete instruction.

Here are the most common reasons this happens and how to fix them:

1. Incomplete Docker Daemon Logs: The Docker daemon, running in the background, might have terminated abruptly or encountered an issue that prevented it from writing its complete log output. When the client tries to read these logs to understand the daemon’s state or a previous command’s output, it hits the "unexpected end of JSON."

  • Diagnosis: Check your Docker daemon logs. The location varies by OS.
    • Linux (systemd): sudo journalctl -u docker.service -f
    • macOS: ~/Library/Containers/com.docker.docker/Data/log/vm/console-Beefy.log (path might vary slightly)
    • Windows: Event Viewer -> Applications and Services Logs -> Docker. Look for any messages indicating crashes, panics, or abrupt shutdowns before the JSON error.
  • Fix: Restart the Docker daemon. This often clears up transient log corruption.
    • Linux: sudo systemctl restart docker
    • macOS/Windows: Quit Docker Desktop and restart it.
  • Why it works: A fresh daemon process will start writing clean log files, and the client will be able to read complete, valid JSON records from the new log stream.

2. Corrupted Docker Image Layers: If a Docker image you’re trying to use has corrupted layers, Docker might struggle to pull or unpack it, leading to incomplete data being sent back to the client, which then manifests as a JSON parsing error.

  • Diagnosis: Try pulling a known-good, small image like hello-world: docker pull hello-world. If this also fails with similar errors or hangs, image corruption is likely. You can also inspect your image cache: docker image ls. Look for images that might have been interrupted during download or build.
  • Fix: Remove corrupted images and re-pull/re-build.
    • First, prune dangling images: docker image prune -a.
    • Then, remove specific suspect images: docker rmi <image_id>.
    • Finally, re-pull or re-build your application’s image.
  • Why it works: By removing the damaged layers or entire images, you force Docker to re-download or re-build them from scratch, ensuring data integrity.

3. Network Interruption During API Communication: Docker clients communicate with the daemon over a socket (Unix domain socket on Linux/macOS, named pipe on Windows). If there’s a network glitch or a firewall rule that intermittently drops packets during an API request/response, the JSON payload can be truncated.

  • Diagnosis: This is harder to pinpoint directly with a command. Observe if the error occurs more frequently when running commands over a VPN, a less stable network, or if you have aggressive network security software. Try running Docker commands from different network locations if possible.
  • Fix: Ensure a stable network connection. If using Docker Desktop, try switching between Wi-Fi and Ethernet, or temporarily disabling VPNs or firewalls to test. For corporate environments, consult your network administrator about potential packet filtering.
  • Why it works: A stable network ensures that the full JSON payload can be transmitted from the daemon to the client without interruption, allowing for proper parsing.

4. Docker CLI Version Mismatch or Bug: Occasionally, a very old or very new, potentially buggy, version of the Docker CLI might have compatibility issues with the Docker daemon, leading to malformed API requests or responses.

  • Diagnosis: Check your Docker CLI version: docker version. Compare it to your Docker daemon version (also shown by docker version). If there’s a significant gap (e.g., CLI is months or years newer/older than the daemon), it’s worth investigating.
  • Fix: Update or downgrade your Docker CLI and daemon to compatible versions. The simplest approach is usually to update Docker Desktop to the latest stable release, which updates both components. If you manage the daemon separately, ensure docker-ce-cli and docker-ce (or equivalent packages) are at matching versions.
    • Linux (apt): sudo apt-get update && sudo apt-get install docker-ce docker-ce-cli containerd.io
  • Why it works: Ensures that both the client and server understand the same API protocols and data formats, preventing misinterpretations that lead to incomplete JSON.

5. Resource Exhaustion on the Docker Host: If the machine running Docker is critically low on memory (RAM) or disk space, the Docker daemon might struggle to complete operations, including serializing responses to the API. This can lead to truncated JSON being sent.

  • Diagnosis: Monitor your system’s resource usage.
    • Linux: free -h for memory, df -h for disk space.
    • macOS: Activity Monitor.
    • Windows: Task Manager. Check if RAM is consistently near 100% or if your Docker data directory (often /var/lib/docker on Linux) is full.
  • Fix: Free up system resources.
    • Close unnecessary applications.
    • Clean up disk space: docker system prune -a --volumes (use with caution, this removes unused data).
    • Increase RAM if possible, or move Docker to a machine with more resources.
  • Why it works: Providing sufficient memory and disk space allows the Docker daemon to operate without errors, ensuring it can properly construct and send complete API responses.

6. Docker Compose Configuration Errors: While less common for this specific error, malformed docker-compose.yml files or incorrect command-line arguments passed to docker-compose can sometimes result in the client sending malformed data or requesting invalid operations, confusing the daemon.

  • Diagnosis: Carefully review your docker-compose.yml for syntax errors (e.g., incorrect indentation, missing colons, invalid characters). Also, check the specific command you ran for typos or incorrect flags. Try running a very simple compose file with a single service to see if the error persists.
  • Fix: Correct any syntax errors in your docker-compose.yml file. Use a YAML linter to validate your file. Ensure your command-line arguments are valid for your Docker Compose version.
  • Why it works: A valid configuration file and correct commands ensure the client sends well-formed requests to the Docker API, which the daemon can then process correctly.

The next error you’ll likely encounter after fixing this is a more specific API error, or if the underlying issue was with a particular image, you might get an error related to image layers or container startup.

Want structured learning?

Take the full Docker course →