Reputation: 1487
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.
Upvotes: 30
Views: 26405
Reputation: 727
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).
Upvotes: 10
Reputation: 31
sudo du -ch $(docker inspect --format='{{.LogPath}}' $(docker ps -qa)) | sort -h | sed 's/\/var\/lib\/docker\/containers\///' | awk '{if ($1 != "total") {split($NF, arr, "/"); id = arr[1]; print $1 " " $2 " " id} else {print $1 " " $2 " " $1}}' | while read size unit id; do if [ "$size" != "total" ]; then name=$(docker ps --format "{{.Names}}" --filter id=$id); echo "$size $unit $name"; else echo "$size $unit $id"; fi; done
for anyone wanting to know what container is filling the docker logs here is a command that will end each line with the container
Upvotes: 3
Reputation: 1487
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"
Upvotes: 63