小知识:docker volume删除卷的操作

prune

要使用此命令,客户端和守护程序API版本都必须至少为1.25。在客户端上使用docker version命令可以检查客户端和守护程序API版本。

?
1
docker volume prune [OPTIONS]

删除未被任何容器使用的本地卷。

OPTIONS

名称,简写 说明 –filter 提供过滤值。 –force , -f 不提示确认信息,直接删除。

rm

要使用此命令,客户端和守护程序API版本都必须至少为1.21。在客户端上使用docker version命令可以检查客户端和守护程序API版本。

?
1
docker volume rm [OPTIONS] VOLUME [VOLUME…]

删除一个或多个卷。从1.25版本起,支持一个选项–force , -f,强制删除一个或多个卷。

补充:docker 移除,裁剪,删除(prune)不使用的镜像、容器、卷、网络

参考docker prune

提供 prune命令,用于移除不使用的镜像、容器、卷、网络。

Prune images

docker image prune移除没有标签并且没有被容器引用的镜像,这种镜像称为 dangling(摇晃的) 镜像。

示例1:docker image prune

删除了redis,无标签且无引用

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#docker ps -a
CONTAINER ID IMAGE  COMMAND CREATED STATUS PORTS  NAMES
# docker images
REPOSITORY    TAG  IMAGE ID  CREATED  SIZE
nginx     latest ae2feff98a0c 4 days ago  133MB
redis     <none> ef47f3b6dc11 8 days ago  104MB
centos     latest 300e315adb2f 12 days ago 209MB
ubuntu     latest f643c72bc252 3 weeks ago 72.9MB
docs/docker.github.io latest 32ed84d97e30 6 months ago 1GB
# docker image prune
# docker images
REPOSITORY    TAG  IMAGE ID  CREATED  SIZE
nginx     latest ae2feff98a0c 4 days ago  133MB
centos     latest 300e315adb2f 12 days ago 209MB
ubuntu     latest f643c72bc252 3 weeks ago 72.9MB
docs/docker.github.io latest 32ed84d97e30 6 months ago 1GB

示例2:移除所有没有容器使用的镜像 -a

?
1
docker image prune -a

跳过警告提示:–force或-f

?
1
docker image prune -f

示例3:执行过滤删除:

超过24小时创建的镜像

?
1
docker image prune -a –filter “until=24h”

关于过滤器的内容,查看 docker image prune手册

移除容器s

当停止容器,不会自动删除,除非在 docker run 时指定了 –rm。一个停止的容器可写层仍然会占用磁盘空间,所以清除它,使用 docker container prune命令。

其他参数类似 docker images prune

移除卷

卷会被一个或多个容器使用,并且占用主机空间。卷不会自动移除,因为自动移除,会破坏数据。

?
1
docker volume prune

其他参数类似 docker images prune

移除网络

Docker 网络不会占用磁盘空间,但是他们创建了 iptables规则,桥接网络服务,路由entries。清除未被容器使用的网络,这么做

?
1
docker network prune

其他参数类似 docker images prune

移除 Everything

docker system prune 命令是一个快捷方式,用于移除镜像,容器,网络。

在 Docker 17.06.0 和更早,卷也是可以移除的。在Docker 17.06.1或更高版本,需要指定参数–volumes。

示例(没有移除卷):

?
1
2
3
4
5
6
7
# docker system prune
WARNING! This will remove:
– all stopped containers
– all networks not used by at least one container
– all dangling images
– all build cache
Are you sure you want to continue? [y/N] y

示例(有了移除卷功能):添加–volumes

?
1
2
3
4
5
6
7
8
# docker system prune –volumes
WARNING! This will remove:
– all stopped containers
– all networks not used by at least one container
– all volumes not used by at least one container
– all dangling images
– all build cache
Are you sure you want to continue? [y/N] y

其他参数类似 docker images prune

以上为个人经验,希望能给大家一个参考,也希望大家多多支持服务器之家。如有错误或未考虑完全的地方,望不吝赐教。

原文链接:https://blog.csdn.net/asty9000/article/details/103408348

声明: 猿站网有关资源均来自网络搜集与网友提供,任何涉及商业盈利目的的均不得使用,否则产生的一切后果将由您自己承担! 本平台资源仅供个人学习交流、测试使用 所有内容请在下载后24小时内删除,制止非法恶意传播,不对任何下载或转载者造成的危害负任何法律责任!也请大家支持、购置正版! 。本站一律禁止以任何方式发布或转载任何违法的相关信息访客发现请向站长举报,会员发帖仅代表会员个人观点,并不代表本站赞同其观点和对其真实性负责。本网站的资源部分来源于网络,如有侵权烦请发送邮件至:2697268773@qq.com进行处理。
建站知识

小知识:docker容器下配置jupyter notebook的操作

2023-3-23 14:21:52

建站知识

小知识:Dockerfile 中 VOLUME 与 docker -v 的区别说明

2023-3-23 14:36:31

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索