---
title: "Overview of Docker Container Logging Drivers: Architecture, Configuration, and Log Rotation"
date: "2026-11-17T11:00:00+07:00"
description: "Master Docker logging drivers including json-file, local, journald, fluentd, log rotation configurations, and non-blocking delivery modes."
author: "AI Assistant"
image: "https://blog.redlinesoft.net/images/post/container-logging-drivers-overview.jpg"
alt: "Architectural overview showing container stdout/stderr streams routed through Docker logging drivers to local files and centralized log aggregators."
tags: ['docker', 'containers', 'logging', 'devops', 'monitoring', 'sysadmin']
---

In Docker, containerized applications write logs directly to standard output (`stdout`) and standard error (`stderr`). The Docker daemon intercepts these streams and routes them through a configurable **logging driver**.

Without proper log rotation and driver configuration, container logs can silently consume all host disk space or stall application threads when remote log servers experience outages.

---

## 1. Docker Logging Architecture

When an application inside a container writes to file descriptor 1 (`stdout`) or file descriptor 2 (`stderr`), the kernel routes the output to the container daemon's log subsystem.

```
Container Process (stdout / stderr)
                |
                v
       Docker Daemon Engine
                |
     +----------+----------+
     | Logging Driver Engine|
     +----------+----------+
                |
   +------------+------------+-----------------------+
   |                         |                       |
   v                         v                       v
[local / json-file]     [journald / syslog]    [fluentd / gelf / awslogs]
(Host Disk Storage)     (System Log Service)   (Remote Log Aggregators)
```

By default, Docker uses the **`json-file`** (or **`local`**) driver, which writes JSON-encoded log messages to `/var/lib/docker/containers/<container-id>/<container-id>-json.log`.

---

## 2. Comprehensive Logging Driver Comparison

| Logging Driver | Target Output Location | `docker logs` Support? | Primary Use Case |
| :--- | :--- | :--- | :--- |
| **`json-file`** | Local JSON disk files | **Yes** | Legacy default. Human-readable JSON log format on host disk. |
| **`local`** | Binary log files on host | **Yes** | Performance-optimized local storage with automatic log rotation. |
| **`journald`** | Systemd `journald` daemon | **Yes** | Linux hosts running `systemd` where central OS logs are merged. |
| **`syslog`** | Syslog daemon / server | No (unless dual-logging) | Enterprise Syslog infrastructure (`rsyslog`, `syslog-ng`). |
| **`gelf`** | Graylog Extended Log Format | No (unless dual-logging) | Streaming logs to Graylog or Logstash endpoints over UDP/TCP. |
| **`fluentd`** | Fluentd daemon | No (unless dual-logging) | Forwarding log events to Fluentd or Fluent Bit collectors. |
| **`awslogs`** | AWS CloudWatch Logs | No (unless dual-logging) | Direct log ingestion into AWS CloudWatch service. |

---

## 3. Configuring Log Rotation and Limits

The most critical operational setting for local logging drivers (`json-file` and `local`) is **log file rotation**. Unrestricted container log growth will eventually fill the host partition (`/var`).

### A. Per-Container Command Line Configuration

Pass `--log-driver` and `--log-opt` flags during `docker run`:

```bash
docker run -d \
  --name web-app \
  --log-driver json-file \
  --log-opt max-size=10m \
  --log-opt max-file=3 \
  nginx:alpine
```

This restricts log storage to a maximum of **3 log files of 10 Megabytes each** (30MB total maximum disk footprint).

### B. Daemon-Wide Global Defaults (`daemon.json`)

To enforce log rotation globally across all newly created containers on a host, configure `/etc/docker/daemon.json`:

```json
{
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "20m",
    "max-file": "5",
    "compress": "true"
  }
}
```

Reload the Docker daemon configuration without restarting active containers:

```bash
sudo systemctl reload docker
```

---

## 4. Preventing Application Stalls: Non-Blocking Delivery Mode

By default, Docker uses **blocking** log delivery (`mode=blocking`). If the logging driver buffer fills up (e.g., when a remote Fluentd or Syslog server becomes unreachable or slow), the container process **blocks on write operations**, causing application threads to freeze.

### Configuring Ring Buffer Delivery (`mode=non-blocking`)

To prevent logging from crashing or slowing down your core application, set the delivery mode to `non-blocking`. This utilizes an in-memory ring buffer:

```bash
docker run -d \
  --name high-throughput-api \
  --log-driver fluentd \
  --log-opt fluentd-address=192.168.1.50:24224 \
  --log-opt mode=non-blocking \
  --log-opt max-buffer-size=4m \
  my-api:latest
```

If the remote log server drops connection, new log messages overflow the 4MB ring buffer and drop safely without stalling application code execution.

---

## 5. Dual-Logging Feature in Modern Docker

Historically, switching to a remote logging driver (like `awslogs` or `fluentd`) disabled the local `docker logs` CLI command.

Modern Docker includes **Dual-Logging**:
- Regardless of the configured remote log driver (`syslog`, `fluentd`, `gelf`), Docker maintains a local cache buffer (`local` driver format).
- Engineers can continue using `docker logs -f <container>` for real-time local debugging while production log pipelines stream data to centralized SIEM / APM platforms.

```bash
# Works even when streaming logs to remote endpoints!
docker logs --tail 50 -f web-app
```

---

## Key Takeaway

**Takeaway:** Container logs written to `stdout`/`stderr` are managed by Docker logging drivers. To prevent host disk exhaustion, always enforce log rotation via `--log-opt max-size` and `max-file` (or in `/etc/docker/daemon.json`). For remote log shipping, set `--log-opt mode=non-blocking` to protect application availability against network timeouts and log collector outages.

---

## Sources

- [Docker Documentation: Configure logging drivers](https://docs.docker.com/config/containers/logging/configure/)
- [Docker Documentation: JSON File logging driver](https://docs.docker.com/config/containers/logging/json-file/)
- [Docker Documentation: Dual-logging capability](https://docs.docker.com/config/containers/logging/dual-logging/)
