
Long-running Docker containers can rapidly accumulate a large number of log lines. These consume storage capacity and reduce performance when accessing and filtering the data. While Docker includes integrated tools for viewing the logs, there’s no built-in mechanism for cleaning them up.
In this article you’ll learn how to clear up the logs of running Docker containers, without restarting or replacing them. You’ll also see some techniques for more efficiently handling large logs while retaining old data.
Understanding the Problem
Docker collects logs from the standard output and error streams of container foreground processes. The docker logs command is used to retrieve these logs but it doesn’t let you delete old lines.
Docker supports many different logging drivers so it’s not possible to offer a standardized clean-up mechanism. This article focuses on the standard json-file logging driver, where log lines are stored in a JSON file on your container host’s filesystem. Refer to your storage driver’s documentation if you need to clean up logs streamed to a remote host.
Log files created by the json-file driver are stored under the /var/lib/docker/containers…
Read Full Article Source