Source From Here
QuestionI read my Docker container log output using "docker logs":
I log lots of data to the log in my node.js app via calls to console.log(). I need to clean the log, because it's gotten too long and the docker logs command first runs through the existing lines of the log before getting to the end. How do I clean it to make it short again?
How-To
First, if you just need to see less output, you can have docker only show you the more recent lines:
Or you can put a number of lines to limit:
To delete the logs on a Docker for Linux install, you can run the following for a single container:
Note that this requires root, and I do not recommend this. You could potentially corrupt the logfile if you null the file in the middle of docker writing a log to the same file. Instead you should configure docker to rotate the logs.
Lastly, you can configure docker to automatically rotate logs with the following in an /etc/docker/daemon.json file:
- {
- "log-driver": "json-file",
- "log-opts": {"max-size": "10m", "max-file": "3"}
- }
沒有留言:
張貼留言