docker空间清理

  |   0 评论   |   0 浏览

常用命令

查看磁盘占用

# docker system df
TYPE                TOTAL               ACTIVE              SIZE                RECLAIMABLE
Images              12                  8                   4.932GB             2.944GB (59%)
Containers          8                   8                   37.69GB             0B (0%)
Local Volumes       7                   7                   14.9GB              0B (0%)

清理磁盘

# docker system prune -a
……………………

Total reclaimed space: 2.737GB

其中清理掉了:

    - all stopped containers
    - all networks not used by at least one container
    - all images without at least one container associated to them
    - all build cache

手动清理命令

删除关闭的容器

docker ps -a | grep Exit | cut -d ' ' -f 1 | xargs docker rm

删除dangling的镜像

docker images | grep "^<none>" | awk "{print3}" | xargs docker rmi

删除dangling的volume

docker volume rm $(docker volume ls -qf dangling=true)

参考