shell - 查看docker最耗磁盘的容器

2023-08-04
#!/bin/bash
### 获取docker磁盘占用最高的top10
num=$1
if [[ -z ${num} ]];then
    num=10
fi
docker_containers=$(docker ps -aq)
du -shm /var/lib/docker/overlay2/* | sort -rnk1 | head -n${num} | while read line
do
    line=($line)
    used_disk=${line[0]}
    dir=${line[1]}
    for docker_container in ${docker_containers}
    do
        docker inspect ${docker_container} | grep ${dir} > /dev/null
        if [[ $? -eq 0 ]];then
        echo -n "容器ID:" ${docker_container}
        echo -n " 容器名:" $(docker ps -a | grep ${docker_container} | awk '{print $NF}')
        echo " 磁盘使用:"${used_disk}"M"
    fi
    done
done

imgv29a7796edf4e34abeb6c66bd8082b86cg.jpg


标题:shell - 查看docker最耗磁盘的容器
地址:https://blog.njqhome.com:8443/articles/2021/10/22/1634881955150.html