非常教程

Docker 17参考手册

引擎: 管理员指南 | Engine: Admin Guide

修剪未使用的Docker对象(引擎) | Prune unused Docker objects (Engine)

Docker对未使用的对象%28(通常称为“垃圾收集”%29)采取保守的清理方法,例如图像、容器、卷和网络:除非明确要求Docker这样做,否则通常不会删除这些对象。这可能导致Docker使用额外的磁盘空间。对于每种类型的对象,Docker提供了一个prune命令。此外,您还可以使用docker system prune一次清除多种类型的对象。本主题演示如何使用这些prune命令。

剪枝图像

docker image prune命令允许您清理未使用的图像。默认情况下,docker image prune只清理悬吊图像。悬空图像是没有标记的,也没有被任何容器引用的图像。若要删除悬挂的图像,请执行以下操作:

$ docker image prune

WARNING! This will remove all dangling images.
Are you sure you want to continue? [y/N] y

若要删除现有容器未使用的所有图像,请使用-a国旗:

$ docker image prune -a

WARNING! This will remove all images without at least one container associated to them.
Are you sure you want to continue? [y/N] y

默认情况下,将提示您继续。若要绕过提示符,请使用-f--force旗子。

使用过滤表达式,可以限制哪些图像被剪除。--filter旗子。例如,仅考虑24小时前创建的图像:

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

还有其他过滤表达式可用。见docker image prune参照系想要更多的例子。

修剪容器

停止容器时,除非使用--rm旗子。若要查看Docker主机上的所有容器,包括已停止的容器,请使用docker ps -a您可能会惊讶于有多少容器存在,特别是在开发系统%21 A中,停止容器的可写层仍然占用磁盘空间。若要清除此问题,可以使用docker container prune命令。

$ docker container prune

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

默认情况下,将提示您继续。若要绕过提示符,请使用-f--force旗子。

默认情况下,所有已停止的容器都将被移除。可以使用--filter旗子。例如,下面的命令只删除已停止的容器,这些容器的时间超过24小时:

$ docker container prune --filter "until=24h"

还有其他过滤表达式可用。见docker container prune参照系想要更多的例子。

修剪量

卷可以由一个或多个容器使用,并占用Docker主机上的空间。卷永远不会自动删除,因为这样做会破坏数据。

$ docker volume prune

WARNING! This will remove all volumes not used by at least one container.
Are you sure you want to continue? [y/N] y

默认情况下,将提示您继续。若要绕过提示符,请使用-f--force旗子。

默认情况下,将删除所有未使用的卷。可以使用--filter旗子。例如,下面的命令只删除未使用keep标签:

$ docker volume prune --filter "label!=keep"

还有其他过滤表达式可用。见docker volume prune参照系想要更多的例子。

修剪网络

Docker网络占用的磁盘空间不多,但它们确实创建了iptables规则、桥接网络设备和路由表条目。要清理这些东西,你可以用docker network prune清理没有被任何容器使用的网络。

$ docker network prune

WARNING! This will remove all networks not used by at least one container.
Are you sure you want to continue? [y/N] y

默认情况下,将提示您继续。若要绕过提示符,请使用-f--force旗子。

默认情况下,所有未使用的网络都将被删除。可以使用--filter旗子。例如,以下命令只删除24小时以上的网络:

$ docker network prune --filter "until=24h"

还有其他过滤表达式可用。见docker network prune参照系想要更多的例子。

修剪所有东西

docker system prune命令是修剪图像、容器和网络的快捷方式。在Docker 17.06.0和更早版本中,卷也会被修剪。在Docker 17.06.1及更高版本中,必须指定--volumesdocker system prune修剪卷。

$ 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

如果您使用的是Docker 17.06.1或更高版本,并且希望也修剪卷,请添加--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

默认情况下,将提示您继续。若要绕过提示符,请使用-f--force旗子。

修剪,修剪,图像,卷,集装箱,网络,盘,行政管理,垃圾收集

引擎: 管理员指南 | Engine: Admin Guide相关

1.Amazon CloudWatch记录日志记录驱动程序(引擎) | Amazon CloudWatch logs logging driver (Engine)
2. 绑定挂载 | Bind mounts (Engine)
3.使用Prometheus(引擎)收集Docker指标 | Collect Docker metrics with Prometheus (Engine)
4.配置和运行Docker(引擎) | Configuring and running Docker (Engine)
5.配置日志记录驱动程序 | Configuring logging drivers (Engine)
6.使用systemd控制和配置Docker(引擎) | Control and configure Docker with systemd (Engine)
7.ETW日志记录驱动程序(引擎) | ETW logging driver (Engine)
8.流利的日志驱动程序(引擎) | Fluentd logging driver (Engine)
9.格式化命令和日志输出(引擎) | Format command and log output (Engine)
10.Google Cloud日志记录驱动程序(引擎) | Google Cloud logging driver (Engine)
11.Graylog扩展格式(GELF)日志记录驱动程序(引擎) | Graylog Extended Format (GELF) logging driver (Engine)
12.Journald日志记录驱动程序(引擎) | Journald logging driver (Engine)
13.JSON文件日志记录驱动程序(引擎) | JSON File logging driver (Engine)
14.在守护进程停机期间保持容器处于活动状态(引擎) | Keep containers alive during daemon downtime (Engine)
15.限制容器的资源(引擎) | Limit a container's resources (Engine)
16.通过大使容器链接(引擎) | Link via an ambassador container (Engine)
17.记录驱动程序的日志标记(引擎) | Log tags for logging driver (Engine)
18.Logentries日志驱动程序(引擎) | Logentries logging driver (Engine)
19.PowerShell DSC用法(引擎) | PowerShell DSC usage (Engine)
20.在容器中运行多个服务(引擎) | Run multiple services in a container (Engine)
21.运行时指标(引擎) | Runtime metrics (Engine)
22.Splunk日志记录驱动程序(引擎) | Splunk logging driver (Engine)
23.自动启动容器(引擎) | Start containers automatically (Engine)
24.存储概述(引擎) | Storage overview (Engine)
25.Syslog日志记录驱动程序(引擎) | Syslog logging driver (Engine)
26.tmpfs mounts
27.解决卷问题(引擎) | Troubleshoot volume problems (Engine)
28.使用日志驱动程序插件(引擎) | Use a logging driver plugin (Engine)
29.使用Ansible(引擎) | Using Ansible (Engine)
30.使用Chef(引擎) | Using Chef (Engine)
31.使用Puppet(引擎) | Using Puppet (Engine)
32.查看容器的日志(引擎) | View a container's logs (Engine)
33.Volumes (Engine)
Docker 17

Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化。容器是完全使用沙箱机制,相互之间不会有任何接口。

主页 https://docker.com/
源码 https://github.com/docker/docker
版本 17
发布版本 17.06