Skip to content

Instantly share code, notes, and snippets.

@stefanpejcic
Created April 28, 2025 10:04
Show Gist options
  • Save stefanpejcic/bd4a0bf86e7e441c3cfca8a75cf84124 to your computer and use it in GitHub Desktop.
Save stefanpejcic/bd4a0bf86e7e441c3cfca8a75cf84124 to your computer and use it in GitHub Desktop.
#!/bin/bash
log_dir="/var/lib/docker/containers"
echo "Container Name | Log Size"
echo "--------------------------"
for log_file in "$log_dir"/*/*-json.log; do
container_id=$(basename "$(dirname "$log_file")")
container_name=$(docker inspect --format='{{.Name}}' "$container_id" 2>/dev/null | sed 's/^\/\(.*\)/\1/')
if [ -z "$container_name" ]; then
continue
fi
log_size=$(du -h "$log_file" | cut -f1)
echo "$container_name | $log_size"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment