设为首页 收藏本站
查看: 537|回复: 0

[经验分享] 删除docker没用的容器,网络,卷,为你的主机“瘦身”

[复制链接]

尚未签到

发表于 2017-10-26 10:40:06 | 显示全部楼层 |阅读模式
Docker takes a conservative(保守的) approach(方法) to cleaning up unused objects(对象) (often referred to(被叫做) as “garbage collection”(垃圾回收)), such as images, containers, volumes, and networks: these objects are generally(通常) not removed unless you explicitly(明确) ask(要求) Docker to do so. This can cause Docker to use extra(额外) disk space. For each type of object, Docker provides a prune command. In addition(此外), you can use docker system prune to clean up multiple types of objects at once. This topic shows how to use these prune commands.
Prune images
The docker image prune command allows you to clean up unused images. By default, docker image prune only cleans up dangling images. A dangling image is one that is not tagged and is not referenced(引用) by any container. To remove dangling images:

To remove all images which are not used by existing containers, use the -a flag:
$ docker image prune -aWARNING! This will remove all images without at least one container associated to them.Are you sure you want to continue? [y/N] y

By default, you are prompted(提示) to continue. To bypass(绕过) the prompt, use the -f or --force flag.    强制删除

You can limit which images are pruned(删除) using filtering(过滤) expressions(表达式) with the --filter flag. For example, to only consider images created more than 24 hours ago:

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

Other filtering expressions are available. See the docker image prune reference for more examples.

Prune containers
When you stop a container, it is not automatically removed unless you started it with the --rm flag. To see all containers on the Docker host, including stopped containers, use docker ps -a. You may be surprised how many containers exist, especially on a development system! A stopped container’s writable layers still take up(占据) disk space. To clean this up, you can use the docker container prune command.

$ docker container pruneWARNING! This will remove all stopped containers.Are you sure you want to continue? [y/N] y

By default, you are prompted to continue. To bypass the prompt, use the -f or --force flag.
By default, all stopped containers are removed. You can limit the scope using the --filter flag. For instance, the following command only removes stopped containers older than 24 hours:
$ docker container prune --filter "until=24h"
Other filtering expressions are available. See the docker container prune reference for more examples.

Prune volumes
Volumes can be used by one or more containers, and take up space on the Docker host. Volumes are never removed automatically, because to do so could(能) destroy(破坏) data.
$ docker volume pruneWARNING! This will remove all volumes not used by at least one container.Are you sure you want to continue? [y/N] y

By default, all unused volumes are removed. You can limit the scope using the --filter flag. For instance, the following command only removes volumes which are not labelled with the keep label(下面的命令只删除未标记为保留标签的卷):
$ docker volume prune --filter "label!=keep"
Other filtering expressions are available. See the docker volume prune reference for more examples.


Prune networks
Docker networks don’t take up much disk space, but they do create iptables rules, bridge network devices, and routing table entries. To clean these things up, you can use docker network prune to clean up networks which aren’t used by any containers().
$ docker network pruneWArNING! This will remove all networks not used by at least one container.Are you sure you want to continue? [y/N] y
By default, you are prompted to continue. To bypass the prompt, use the -f or --force flag.
By default, all unused networks are removed. You can limit the scope using the --filter flag. For instance, the following command only removes networks older than 24 hours:

Prune everything
The docker system prune command is a shortcut that prunes images, containers, and networks. In Docker 17.06.0 and earlier, volumes are also pruned. In Docker 17.06.1 and higher, you must specify the --volumes flag for docker system prune to prune volumes.
$ docker system pruneWARNING! This will remove:        - all stopped containers        - all networks not used by at least one container        - all dangling images        - all build cacheAre you sure you want to continue? [y/N] y
If you are on Docker 17.06.1 or higher and want to also prune volumes, add the --volumes flag:
$ docker system prune --volumesWARNING! 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 cacheAre you sure you want to continue? [y/N] y


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-405942-1-1.html 上篇帖子: Docker报错 WARNING: IPv4 forwarding is disabled. Networking will not work. 下篇帖子: Docker swarm部署
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表