wukong
wukong

Reputation: 2597

Is it safe to delete docker logs generated at /var/lib/docker/containers/HASH

The log is now is currently 13GB, I don't know if it safe to delete the log, and how to make the log smaller

root@faith:/var/lib/docker/containers/f1ac17e833be2e5d1586d34c51324178bd18f969d
1046cbb59f10eaa4bcf84be# ls -alh
total 13G
drwx------ 2 root root 4.0K Mar  6 08:35 .
drwx------ 3 root root 4.0K Feb 24 11:00 ..
-rw-r--r-- 1 root root 2.1K Feb 24 10:15 config.json
-rw------- 1 root root  13G Feb 25 00:27 f1ac17e833be2e5d1586d34c51324178bd18f96
9d1046cbb59f10eaa4bcf84be-json.log
-rw-r--r-- 1 root root  611 Feb 24 10:15 hostconfig.json
-rw-r--r-- 1 root root   13 Feb 24 10:15 hostname
-rw-r--r-- 1 root root  175 Feb 24 10:15 hosts
-rw-r--r-- 1 root root   61 Feb 24 10:15 resolv.conf
-rw-r--r-- 1 root root   71 Feb 24 10:15 resolv.conf.hash

Upvotes: 3

Views: 4940

Answers (2)

larsks
larsks

Reputation: 311606

Congratulations, you have discovered one of The Big Unsolved Problems with Docker!

As Nathaniel says, Docker assumes it has complete ownership of things under /var/lib/docker so trying to delete files there from behind Docker's back may not work.

However, based on components in issue 7333 and in PR 9753, it looks like people are successfully using logrotate and the copytruncate directive to rotate docker logs. Both these links are worth reading, because they contain a long discussion about the pitfalls of Docker logging and some potential solutions.

Ideally, Docker itself would have much better native support for log management. Until then, here are some alternatives to consider:

If you control the source for your applications, you can configure everything to log to syslog rather than to stdout/stderr. You can then have a variety of solutions you can pursue, from running a syslog service inside your container to exposing the hosts's /dev/log inside the container.

Another options is to run systemd inside your container, and use this to start your services. systemd will collect stdout/stderr from your services and feed that to journald, and journald will take care of things like log rotation (and also give you a reasonably flexible mechanism for querying the logs).

Upvotes: 7

Nathaniel Waisbrot
Nathaniel Waisbrot

Reputation: 24483

These ought to be cleaned up when you delete the container. (Thus, it is not OK to delete them, because Docker believes that it has control of /var/lib/docker.)

Upvotes: 2

Related Questions