Tackling Docker Container Log Bloat: Identify, Fix, Prevent

Container log bloat is a hidden culprit behind full disks on Docker hosts. Learn how to spot oversized logs, clean them up, and configure rotation so they never grow out of control again.

Table of Contents

Docker is a fantastic way to package and run applications, but one of the less obvious issues you might run into is container log bloat. By default, Docker uses the json-file log driver, which means every container writes logs to a JSON file on disk. If left unchecked, these logs can grow to hundreds of gigabytes and fill up your host storage.

In this post, we’ll walk through how to:

  1. Identify containers with oversized logs.
  2. Fix the issue to reclaim space.
  3. Prevent it from happening again.

Step 1: Identify the Culprit

Container logs are stored under /var/lib/docker/containers/<container-id>/. Each container has a file named <container-id>-json.log that grows as logs are written.

To find the biggest offenders:

To map the container ID to a name:

You can also get a summary of Docker disk usage:


Step 2: Fix the Problem

If you’ve found a multi-gigabyte log file, you can reclaim the space immediately.

Option A — Truncate the log file (no restart required):

Option B — Restart the container:

Option C — Use logrotate:
Create /etc/logrotate.d/docker-containers:

Then force a run:


Step 3: Prevent Future Log Bloat

The best long-term fix is to configure Docker’s logging options.

Edit /etc/docker/daemon.json:

Restart Docker:

This caps each container log at ~250 MB (5 × 50 MB).

If you’re using Docker Compose, you can set per-service options:


Step 4: Additional Cleanup

Sometimes the logs aren’t the only issue. You can also:

  • Remove dangling build cache:
  • Remove unused containers, networks, images, and volumes:

    (Warning: removes unused volumes, so double-check before running!)
  • Check overlay2 and volumes for large files:

Conclusion

Container log bloat is one of the most common reasons Docker hosts run out of disk space. The good news is that it’s easy to diagnose and fix:

  • Identify large log files under /var/lib/docker/containers.
  • Fix by truncating or rotating logs.
  • Prevent by setting log rotation defaults in Docker.

Taking these steps will keep your Docker hosts running smoothly and ensure you don’t wake up to a full disk in production.


Have you run into container log bloat in your environment? What strategies worked best for you? Share your experience in the comments below!

Have a project or a problem?

Talk with a senior engineer for practical recommendations—no obligation.

Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Categories

Get a free consultation from Reliable Penguin

Submit the form—or for immediate service call 866-649-7984.