Docker clean log files

the log files of docker container are located in

/var/lib/docker/containers/*containeNname*/*logFileName*-josn.log 

After a while of using docker, the log files becomes larger , so the need to empty the logs , to do so , we will truncate all the log files instead of deleting them , because deleting them will cause an error of 'no such file or directory' when trying to check  the logs.

sudo sh -c "truncate -s 0 /var/lib/docker/containers/*/*-json.log"

or you can configure docker-compose to limit the size of the logs of a container

image: my_docker_image
logging:
    driver: "json-file"
    options:
        max-size: "20m"
        max-file: "5"

you can also passe it as argument when running a container with docker run

docker run --log-opt max-size=20m --log-opt max-file=5 my_docker_image