Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to list docker logs size for all containers?

Tags:

docker

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.

like image 622
user12341234 Avatar asked Sep 03 '25 06:09

user12341234


2 Answers

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"
like image 162
user12341234 Avatar answered Sep 04 '25 21:09

user12341234


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).

like image 37
AntonioK Avatar answered Sep 04 '25 20:09

AntonioK