Source From Here
QuestionI use docker logs [container-name] to see the logs of a specific container. Is there an elegant way to clear these logs?
HowTo
First the bad answer. From this question there's a one-liner that you can run:
instead of echo, there's the simpler:
or there's the truncate command:
I'm not a big fan of either of those since they modify Docker's files directly. The external log deletion could happen while docker is writing json formatted data to the file, resulting in a partial line, and breaking the ability to read any logs from the docker logs cli. For an example of that happening, see this comment on duketwo's answer
Instead, you can have Docker automatically rotate the logs for you. This is done with additional flags to dockerd if you are using the default JSON logging driver:
You can also set this as part of your daemon.json file instead of modifying your startup scripts:
- {
- "log-driver": "json-file",
- "log-opts": {"max-size": "10m", "max-file": "3"}
- }
沒有留言:
張貼留言