怎么在docker中使用volume命令删除卷
本篇文章为大家展示了怎么在docker中使用volume命令删除卷,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。
prune
要使用此命令,客户端和守护程序API版本都必须至少为1.25。在客户端上使用docker version命令可以检查客户端和守护程序API版本。
dockervolumeprune[OPTIONS]
删除未被任何容器使用的本地卷。
OPTIONS
名称,简写 | 说明 |
--filter | 提供过滤值。 |
--force , -f | 不提示确认信息,直接删除。 |
rm
要使用此命令,客户端和守护程序API版本都必须至少为1.21。在客户端上使用docker version命令可以检查客户端和守护程序API版本。
dockervolumerm[OPTIONS]VOLUME[VOLUME...]
删除一个或多个卷。从1.25版本起,支持一个选项--force , -f,强制删除一个或多个卷。
补充:docker 移除,裁剪,删除(prune)不使用的镜像、容器、卷、网络
参考docker prune
提供 prune命令,用于移除不使用的镜像、容器、卷、网络。
Prune images
docker image prune移除没有标签并且没有被容器引用的镜像,这种镜像称为 dangling(摇晃的) 镜像。
示例1:docker image prune
删除了redis,无标签且无引用
#dockerps-a CONTAINERIDIMAGECOMMANDCREATEDSTATUSPORTSNAMES #dockerimages REPOSITORYTAGIMAGEIDCREATEDSIZE nginxlatestae2feff98a0c4daysago133MB redis<none>ef47f3b6dc118daysago104MB centoslatest300e315adb2f12daysago209MB ubuntulatestf643c72bc2523weeksago72.9MB docs/docker.github.iolatest32ed84d97e306monthsago1GB #dockerimageprune #dockerimages REPOSITORYTAGIMAGEIDCREATEDSIZE nginxlatestae2feff98a0c4daysago133MB centoslatest300e315adb2f12daysago209MB ubuntulatestf643c72bc2523weeksago72.9MB docs/docker.github.iolatest32ed84d97e306monthsago1GB
示例2:移除所有没有容器使用的镜像 -a
dockerimageprune-a
跳过警告提示:--force或-f
dockerimageprune-f
示例3:执行过滤删除:
超过24小时创建的镜像
dockerimageprune-a--filter"until=24h"
关于过滤器的内容,查看 docker image prune手册
移除容器s
当停止容器,不会自动删除,除非在 docker run 时指定了 --rm。一个停止的容器可写层仍然会占用磁盘空间,所以清除它,使用 docker container prune命令。
其他参数类似 docker images prune
移除卷
卷会被一个或多个容器使用,并且占用主机空间。卷不会自动移除,因为自动移除,会破坏数据。
dockervolumeprune
其他参数类似 docker images prune
移除网络
Docker 网络不会占用磁盘空间,但是他们创建了 iptables规则,桥接网络服务,路由entries。清除未被容器使用的网络,这么做
dockernetworkprune
其他参数类似 docker images prune
移除 Everything
docker system prune 命令是一个快捷方式,用于移除镜像,容器,网络。
在 Docker 17.06.0 和更早,卷也是可以移除的。在Docker 17.06.1或更高版本,需要指定参数--volumes。
示例(没有移除卷):
#dockersystemprune WARNING!Thiswillremove: -allstoppedcontainers -allnetworksnotusedbyatleastonecontainer -alldanglingimages -allbuildcache Areyousureyouwanttocontinue?[y/N]y
示例(有了移除卷功能):添加--volumes
#dockersystemprune--volumes WARNING!Thiswillremove: -allstoppedcontainers -allnetworksnotusedbyatleastonecontainer -allvolumesnotusedbyatleastonecontainer -alldanglingimages -allbuildcache Areyousureyouwanttocontinue?[y/N]y
其他参数类似 docker images prune
上述内容就是怎么在docker中使用volume命令删除卷,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注恰卡编程网行业资讯频道。