Docker删除大量停止的container

1. 怎么做

官方建议的批量删除停止容器使用docker rm $(sudo docker ps -a -q)

千万不要用 docker rm -f $(sudo docker ps -a -q),会删除全部容器的

2. 为什么这么做

1. docker ps -a -q

docker ps 命令的解释:

docker ps -a -q 列出所有容器的数字ID

root@haha:~# docker ps --help

Usage:  docker ps [OPTIONS]

List containers

Options:
  -a, --all             Show all containers (default shows just running)
  -f, --filter value    Filter output based on conditions provided (default [])
      --format string Pretty-print containers using a Go template --help Print usage -n, --last int Show n last created containers (includes all states) (default -1) -l, --latest Show the latest created container (includes all states) --no-trunc Don't truncate output -q, --quiet Only display numeric IDs -s, --size Display total file sizes

具体看看,docker ps 是列出容器的命令

  • -a 列出所有的容器
  • -q 只显示数字ID 

2. docker rm命令的解释:

root@haha:~# docker rm --help

Usage:  docker rm [OPTIONS] CONTAINER [CONTAINER...]

Remove one or more containers

Options:
  -f, --force     Force the removal of a running container (uses SIGKILL)
      --help      Print usage -l, --link Remove the specified link -v, --volumes Remove the volumes associated with the container
  • -f 强制删除,可以删除正在运行的容器

  • -v 容器启动后,数据会以volumes的形式存在于硬盘中,即使删除了container数据也不会删除,加上这个参数那么容器执行的数据也会被删除 

 

 

 

转载于:https://www.cnblogs.com/liuzhipeng/p/7525811.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值