Docker Certified Associate Exam Course
Docker Engine
Demo Logging Driver
In this tutorial, you’ll learn how to manage Docker’s logging drivers—check the default, switch the daemon-wide setting, apply advanced options, and override the driver for individual containers.
1. Check the Default Logging Driver
Docker uses the json-file
driver by default, storing container logs as JSON on the host.
# Verify the current logging driver
docker system info | grep -i "logging driver"
# Output: Logging Driver: json-file
Note
The json-file
driver is the standard Docker logging backend. It’s easy to parse and works out of the box.
2. Create and Inspect a Test Container
Run an Ubuntu container to see its inherited log configuration:
# Start a detached Ubuntu container
docker container run -itd --name test-container ubuntu
Inspect its log settings:
docker container inspect test-container \
--format='{{json .HostConfig.LogConfig}}'
# Output:
# {
# "Type": "json-file",
# "Config": {}
# }
3. Supported Logging Drivers
Docker supports multiple logging backends for different use cases. You can find the full list in the official docs:
Configure containers → Logging
Driver | Use Case |
---|---|
json-file | Local JSON logs, simple parsing |
syslog | Centralized logging to syslog daemon |
journald | Integration with systemd’s journal |
fluentd | Forward logs to a Fluentd collector |
awslogs | Ship logs to Amazon CloudWatch Logs |
splunk | Send logs to a Splunk HTTP Event Collector (HEC) |
… | And others (gcplogs, logentries, etc.) |
4. Change the Default Driver to Syslog
To switch the daemon-wide driver to syslog
, edit /etc/docker/daemon.json
:
Warning
Modifying daemon.json
requires restarting the Docker daemon. Existing containers will continue using their current driver until recreated.
- Stop Docker:
sudo systemctl stop docker
- Update
/etc/docker/daemon.json
:{ "log-driver": "syslog" }
- Restart Docker:
sudo systemctl start docker
- Verify:
docker system info | grep -i "logging driver" # Output: Logging Driver: syslog
5. Advanced Logging Options
You can fine-tune log behavior with log-opts
. For example, to limit file size and rotation on json-file
:
{
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "3"
},
"labels": "production_status",
"env": "os_customer"
}
Retrieve the current default driver in scripts:
docker info --format '{{.LoggingDriver}}'
# e.g., json-file
6. Override the Logging Driver per Container
Even when the daemon default is syslog
, you can pick a different driver for a specific container:
docker container run -itd \
--name logtest \
--log-driver journald \
ubuntu
Confirm the override:
docker container inspect logtest \
--format='{{json .HostConfig.LogConfig}}'
# Output:
# {
# "Type": "journald",
# "Config": {}
# }
7. Conclusion
You’ve learned how to:
- Check and view Docker’s default logging driver
- Change the daemon-wide driver in
/etc/docker/daemon.json
- Apply advanced options like rotation and size limits
- Override logging drivers for individual containers
Happy logging!
References
Watch Video
Watch video content