[Docker基础]如何清除不用的资源

时间:2022-05-15 12:42:44

Docker - How to cleanup resources

有时你可能需要清理Docker中不用的资源,特别是在学习Docker过程中创建的镜像、容器、网络、存储卷等。

delete volumes

  • 删除挂载的存储卷
$ docker volume rm $(docker volume ls -qf )

delete networks

  • 删除创建的网络
$ docker network ls
$ docker network ls | grep "bridge"
$ docker network rm $(docker network ls | grep "bridge" | awk '//{print $1}')
$ docker network ls | awk '$3 == "bridge" && $2 != "bridge" { print $1 }'

delete images

  • 删除镜像(删除镜像前需要停止所运行的容器并删除容器)
$ docker images
$ docker rmi $(docker images --filter "dangling=true" -q --no-trunc)
$ docker rmi $(docker images | grep "none" | awk '//{print $3}')

delete containers

  • 删除容器
$ docker ps
$ docker ps -a
$ docker rm $(docker ps -qa --no-trunc --filter "status=exited")

resize disk space for docker vm

$ docker-machine create --driver virtualbox --virtualbox-disk-size "40000" default