If you do docker container ls --size
it doesn't show the size of the logs, which might be taking all your space and you don't even know.
Here is the command
sudo du -h $(docker inspect --format='{{.LogPath}}' $(docker ps -qa))
Also a good way to prevent logs from taking all your space is to add this to your docker-compose
logging:
driver: "json-file"
options:
max-size: "100m"
max-file: "5"
Size of logs for each docker container, sorted by size:
# without total:
sudo du -h $(docker inspect --format='{{.LogPath}}' $(docker ps -qa)) | sort -h
# with total:
sudo du -ch $(docker inspect --format='{{.LogPath}}' $(docker ps -qa)) | sort -h
Total size of all docker containers logs in one line:
# human-readable:
sudo du -ch $(docker inspect --format='{{.LogPath}}' $(docker ps -qa)) | tail -n1
# in Mbytes (suitable for monitoring scripts):
sudo du -cm $(docker inspect --format='{{.LogPath}}' $(docker ps -qa)) | tail -n1
Will cause error if you don't have any docker containers (docker ps -qa
output is empty).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With