Tech Tip: docker logs

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?

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:

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

Truncate

For single container:

For multiple logs