If you are running containers on a linux environment, by default the docker engine produces daemon logs stored in different location based on the linux flavour. If a container is high usage like delegate or is up for a long time, setting up a log rotate mechanism is very important to avoid disk crashing.
Some ways to achieve this is via:
1. Logrotate utility -
---------- On Debian and Ubuntu ----------
sudo apt-get update && apt-get install logrotate -y
---------- On CentOS, RHEL and Fedora ----------
yum update && yum install logrotate
The logs which are filling up are /var/lib/docker/containers/[CONTAINER ID]/[CONTAINER_ID]-json.log therefore:
Create a new logrotate file /etc/logrotate.d/docker-container and a conf file at /etc/logrotate.conf add same line to both as below:
/var/lib/docker/containers/*/*.log { rotate 5 daily compress missingok delaycompress copytruncate}
This will rotate the files daily and keep a max of 3 files in the directory
/var/lib/docker/containers/*
and run
cat /dev/null > /var/lib/docker/containers/CONTAINER_ID/CONTAINER_ID-json.log #this is to clear out the existing logfile
2. Adding logging rule in docker run:
If you’re using are using the docker image delegate what they need to do is:
a) stop the docker container i.e. sudo docker stop && sudo docker rm
b) inside the harness-delegate-docker/ folder modify our launch script i.e. launch-harness-delegate.sh by adding following lines to it:
–log-driver json-file --log-opt max-size=100m --log-opt max-file=5 the docker run should look something like:
sudo docker run -d --restart unless-stopped --log-driver json-file --log-opt max-size=100m --log-opt max-file=5 --hostname=$(hostname -f)
…
This would keep a maximum of 5 files with a max size of 100mb
c) then run
cat /dev/null > /var/lib/docker/containers/CONTAINER_ID/CONTAINER_ID-json.log #this is to clear out the existing logfile
d) Finally re-run the script i.e. ./ launch-harness-delegate.sh
You can modify the days or size values according to your infra availability to keep it as clean as possible.
Or if you want to stop daemon logging altogether the in the daemon.json file
Operating system | Location |
---|---|
RHEL, Oracle Linux | /var/log/messages |
Debian | /var/log/daemon.log |
Ubuntu 16.04+, CentOS | Use the command journalctl -u docker.service or /var/log/syslog |
Ubuntu 14.10- | /var/log/upstart/docker.log |
macOS (Docker 18.01+) | ~/Library/Containers/com.docker.docker/Data/vms/0/console-ring |
macOS (Docker <18.01) | ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/console-ring |
Windows | AppData\Local |
You can set
"log-driver": "none",