user12341234
user12341234

Reputation: 1487

How to list docker logs size for all containers?

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

Answers (3)

AntonioK
AntonioK

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

user27288230
user27288230

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

user12341234
user12341234

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

Related Questions