This tech tip regards logging file handling and its troubleshooting.

About docker logging

Every container (linux based), places its stdout to a log file located in /var/lib/docker/container/<container_inspect_id>/<file>-json.log .

Every time you call the function docker logs <container_id> you I’ll see the content of its file. This function with –f option acts like tail, it shows all file content and waits for new log contents (follow mode). This could be useful for troubleshooting; but during the time, in some “verbose” container, the log file could become huge. In fact after some months, docker logs will show you the whole content from the beginning of the container creation.

Where to find a specific container log?

docker inspect container_id | grep "LogPath"

image

File reduction becomes critical in some scenario. The solutions to reduce this file are simply 2 (until now):

  • log rotation
  • truncate file

Log rotation

Simply place a file a “docker-container” file in /etc/logrotate.d/ with this content:

/var/lib/docker/containers/*/*.log {
  rotate 7
  daily
  compress
  size=1M
  missingok
  delaycompress
  copytruncate
}

Source: https://sandro-keil.de/blog/2015/03/11/logrotate-for-docker-container/

Truncate

For single container:

truncate -s 0 /var/lib/docker/containers/container_id/file-json.log

For multiple logs

truncate -s 0 /var/lib/docker/containers/*/*-json.log

 

By admin

Utilizzando il sito, accetti l'utilizzo dei cookie da parte nostra. Using this site you accept cooking utilization. maggiori informazioni more Informations

Questo sito utilizza i cookie per fornire la migliore esperienza di navigazione possibile. Continuando a utilizzare questo sito senza modificare le impostazioni dei cookie o cliccando su "Accetta" permetti il loro utilizzo. This site uses cookies to provide the best browsing experience possible. By continuing to use this website without changing your cookie settings or clicking "Accept" allow their use.

Chiudi Close