Sub topic 3
The Local Driver: Compact Storage with Rotation by Default
Assume you can run containers, use a Linux shell, and read basic Docker Compose files. This chapter focuses on choosing and checking Docker logging storage.
The local driver
The local logging driver stores container output on the Docker host in a compact format. It rotates logs automatically, so it is usually safer than the default json-file driver when you want local logs without unlimited disk growth.
You can configure limits explicitly:
docker run -d --name api \
--log-driver local \
--log-opt max-size=10m \
--log-opt max-file=3 \
nginx:alpineThis keeps each log file near 10 MB and retains up to three files. The local driver still supports docker logs.
Verify settings and troubleshoot
Check the daemon's default driver:
docker info --format '{{.LoggingDriver}}'Check the driver and options attached to an existing container:
docker inspect --format '{{json .HostConfig.LogConfig}}' apiA daemon default affects newly created containers. Changing daemon.json does not change containers that already exist. Recreate those containers with the new settings. If the disk is already full, find large container log directories before starting more workloads, then apply rotation and clean up according to your operational policy.
Blocking versus non-blocking delivery
Blocking delivery waits for the logging destination. A slow remote system can therefore delay the application. Non-blocking delivery buffers messages in memory and lets the application continue, but messages can be lost when the buffer fills or the container stops.
For a remote driver, configure non-blocking delivery deliberately:
docker run -d --name worker \
--log-driver syslog \
--log-opt syslog-address=udp://192.0.2.10:514 \
--log-opt mode=non-blocking \
--log-opt max-buffer-size=4m \
nginx:alpineSending logs to remote systems
Remote drivers such as syslog, journald, fluentd, and awslogs send output outside the host. They support central search and retention, but require network availability, credentials, and monitoring. Choose blocking mode when losing logs is worse than possible application backpressure. Choose non-blocking mode when application availability matters more.
Dual logging and `docker logs`
Some remote-driver configurations can keep a local cache so that docker logs continues to work while logs are also sent remotely. Confirm the driver and cache behavior for your Docker version and deployment. Treat the remote system as the source for long-term retention and the local cache as a troubleshooting aid.
Exercise
A container uses a remote driver, but docker logs returns no useful output. What should you check first?
Show answer
Inspect .HostConfig.LogConfig to verify the driver and options, then check whether dual logging or a local cache is enabled.