当前位置: 首页 > news >正文

docker下移除不使用的镜像、容器、卷、网络

Prune images

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

示例1:docker image prune

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

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

docker image prune -a

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

docker image prune -f

示例3:执行过滤删除:

超过24小时创建的镜像

docker image prune -a --filter "until=24h"

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

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

其他参数类似 docker images prune

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

docker volume prune

其他参数类似 docker images prune

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

docker network prune

其他参数类似 docker images prune

移除 Everything

docker system prune

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

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

示例(没有移除卷):

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

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

http://www.lryc.cn/news/239013.html

相关文章:

  • C语言基本算法之选择排序
  • 服务器数据恢复—raid5上层NTFS分区误删除/格式化的数据恢复案例
  • 【漏洞复现】IP-guard WebServer 存在远程命令执行漏洞
  • 人工智能学习阶段有哪些?
  • vue 中为什么需要虚拟DOM、VDOM 是如何生成的、VDOM 如何做 diff 的?
  • 数据分析思维与模型:相关分析法
  • 【算法萌新闯力扣】:两句话中的不常见单词
  • Xilinx Zynq-7000系列FPGA任意尺寸图像缩放,提供两套工程源码和技术支持
  • 基于 Glibc 版本升级的 DolphinDB 数据查询性能优化实践
  • 【顺序表的应用-通讯录的实现】
  • [Spring Cloud] Nacos 实战 + Aws云服务器
  • SpringCloud微服务注册中心:Nacos介绍,微服务注册,Ribbon通信,Ribbon负载均衡,Nacos配置管理详细介绍
  • 身份证号码校验
  • ArcGIS如何处理并加载Excel中坐标数据?
  • C++标准模板(STL)- 类型支持 (类型修改,从给定类型移除 const 或/与 volatile 限定符,std::remove_cv)
  • nodejs搭建本地服务
  • 如何看待Unity新收费模式?
  • Excel数据可视化—波士顿矩阵图【四象限图】
  • 【Java】智慧工地管理系统源代码,支持二次开发,SaaS模式
  • Lstm+transformer的刀具磨损预测
  • 本机idea连接虚拟机中的Hbase
  • .NET中的Object类学习3_MemberwiseClone方法
  • 鼎捷前端开发校招岗技术面面经(已过)
  • Rockchip平台rk3588源码下载编译(基于Android13)
  • RuntimeError: PyPI no longer supports ‘pip search‘ (or XML-RPC search).
  • 21款奔驰GLS450升级23P驾驶辅助 提升安全出行
  • iOS越狱检测总结
  • 场景驱动的 AI 体验设计:如何让智能 IDE 赋能遗留系统重写
  • 【封装UI组件库系列】搭建项目及准备工作
  • C#使用DateTime获取日期和时间