Configuring Docker Container Logging
Configuring the Logging Driver
To configure the logging driver for a Docker container, you can use the --log-driver
option when running the container. For example, to use the syslog
logging driver:
docker run -d --name my-app --log-driver=syslog my-app:latest
You can also set the default logging driver for the entire Docker daemon by modifying the /etc/docker/daemon.json
file:
{
"log-driver": "syslog"
}
After making the changes, restart the Docker daemon for the new configuration to take effect.
Configuring Logging Options
Each logging driver supports different logging options that you can use to customize the logging behavior. For example, the syslog
logging driver supports the following options:
Option |
Description |
syslog-address |
The address of the syslog server. |
syslog-facility |
The syslog facility to use. |
syslog-format |
The syslog message format to use. |
syslog-tag |
The tag to add to the log message. |
To set the logging options for a container, use the --log-opt
flag:
docker run -d --name my-app --log-driver=syslog --log-opt syslog-address=tcp://192.168.1.100:514 my-app:latest
By configuring the logging options, you can customize the logging behavior to suit your specific requirements, such as sending logs to a remote syslog server or using a specific log message format.