Pcornel
Browse topics
Options
Recent
Favorites
Containers · Technical reference

Container Logs and Log Drivers

Direct answer

Container logs are the process's stdout/stderr captured by the runtime via a log driver (json-file, journald, local, fluentd…) or, on Kubernetes, files on the node collected by a log agent.

When to use this

Use it when logs are missing, too large or not shipped centrally.

First 30 seconds

1. docker logs <c> / kubectl logs.

2. Log driver: docker inspect --format '{{.HostConfig.LogConfig}}' <c>.

3. Rotation set in /etc/docker/daemon.json.

4. Central agent (Fluent Bit/Vector) running?

5. Logs reach the platform.

Operational verification

stdout/stderr → log driver/node file → rotation → agent → central store

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
Docker / containerd / Podman / Kubernetes / OCI-compatible platforms
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformDocker / containerd / Podman / Kubernetes / OCI-compatible platforms
Scope / prerequisiteUse it when logs are missing, too large or not shipped centrally.
What next?2 suggested next steps
Evidence0
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

2 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 How to verify Verify boundary

Set log-opts max-size and max-file, then recreate containers and confirm with docker inspect. Confirm the collector reads the same location the driver writes to.

Step 2 Common failures Narrow the fault

Changing daemon.json does not affect existing containers. Logging to a file inside the container hides logs from docker logs and the collector. Very chatty debug logging can slow the application because writes block when the driver is slow.

Key points

Apps should log to stdout/stderr. Configure log rotation (max-size, max-file) or disks fill up. Kubernetes keeps only the current and previous container logs locally.

Key checks
  • docker ps -a — containers and exit codes
  • docker logs <c> — container output
  • docker inspect <c> — config, mounts, network, state
ReferenceWhat it is1 section · depth on demand

How it works

The runtime reads the container's stdout and stderr streams and passes each line to the log driver. Defaults are set in /etc/docker/daemon.json under log-driver and log-opts and apply only to new containers.

ReferenceImportant terms & boundaries3 sections · depth on demand

Log drivers

DriverNotes
json-file (default)Rotate with max-size/max-file or disks fill up
localCompressed, rotated by default
journaldLogs in systemd journal
syslog, fluentd, gelf, awslogsShip to central systems
{ "log-driver": "local", "log-opts": { "max-size": "50m", "max-file": "5" } }

Set in /etc/docker/daemon.json. Applications should log to stdout/stderr, not files inside the container.

In depth

Container logs are whatever the process writes to stdout and stderr. The log driver decides where those lines go; docker logs only works with drivers that also keep a local copy (json-file, local, journald, or any driver when dual logging is active).

Daemon-wide defaults with rotation

{
  "log-driver": "local",
  "log-opts": { "max-size": "20m", "max-file": "5" }
}

Save as /etc/docker/daemon.json, restart Docker, then recreate containers — existing containers keep the settings they were created with.

Delivery mode

ModeBehaviour when the destination is slow
blocking (default)The application's writes block; a stuck remote driver can stall the app
non-blocking + max-buffer-sizeLines are buffered and dropped when the buffer is full

Use non-blocking for remote drivers (syslog, fluentd, gelf) when application availability matters more than every log line.

Kubernetes

The kubelet and runtime write container logs to /var/log/pods/<ns>_<pod>_<uid>/<container>/N.log and rotate them with containerLogMaxSize and containerLogMaxFiles in the kubelet configuration. A node log agent (DaemonSet) tails those files; kubectl logs reads them through the kubelet.

Worked check — where is the disk going?

du -sh /var/lib/docker/containers/*/*-json.log | sort -h | tail -3
docker inspect -f '{{.HostConfig.LogConfig}}' <container>
Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

Common mistakes

  • json-file logs without rotation filling the disk.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Terminology layer

Terms & aliases

Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.

Aliases that resolve here
container logs and log driversdocker logs log driverjson-file max-size
Confirmation

Confirm action

Continue?