
上QQ阅读APP看书,第一时间看更新
Advanced topic – changing the default logging driver
Let's change the default logging driver of a Linux host:
- The easiest way to do this is on a real Linux host. For this purpose, we're going to use Vagrant with an Ubuntu image:
$ vagrant init bento/ubuntu-17.04 $ vagrant up $ vagrant ssh
Vagrant is an open source tool developed by Hashicorp that is often used for building and maintaining portable virtual software development environments.
- Once inside the Ubuntu VM, we want to edit the Docker daemon configuration file. Navigate to the /etc/docker folder and run vi as follows:
$ vi daemon.json
- Enter the following content:
{
"Log-driver": "json-log",
"log-opts": {
"max-size": "10m",
"max-file": 3
}
}
- Save and exit vi by first pressing Esc and then typing :w:q and finally hitting the Enter key.
The preceding definition tells the Docker daemon to use the json-log driver with a maximum log file size of 10 MB before it is rolled, and the maximum number of log files that can be present on the system is 3 before the oldest file gets purged.
Now we have to send a SIGHUP signal to the Docker daemon so that it picks up the changes in the configuration file:
$ sudo kill -SIGHUP $(pidof dockerd)
Note that the preceding command only reloads the config file and does not restart the daemon.