Use it when logs are missing, too large or not shipped centrally.
Container Logs and Log Drivers
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.
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.
stdout/stderr → log driver/node file → rotation → agent → central store
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
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.
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.
docker ps -a— containers and exit codesdocker logs <c>— container outputdocker 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
| Driver | Notes |
|---|---|
| json-file (default) | Rotate with max-size/max-file or disks fill up |
| local | Compressed, rotated by default |
| journald | Logs in systemd journal |
| syslog, fluentd, gelf, awslogs | Ship 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
| Mode | Behaviour when the destination is slow |
|---|---|
blocking (default) | The application's writes block; a stuck remote driver can stall the app |
non-blocking + max-buffer-size | Lines 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>
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
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.