Current Article:

How to clear the logs for a Docker container?

How to clear the logs for a Docker container?

Simple way, but not recommended (modifing Docker’s files directly could lead to errors):

echo "" > $(docker inspect --format='{{.LogPath}}' <container_name_or_id>)

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:

dockerd ... --log-opt max-size=10m --log-opt max-file=3