本文共 10093 字,大约阅读时间需要 33 分钟。
docker数据卷容器卷
Docker makes it easy to wrap your applications and services in containers so you can run them anywhere. As you work with Docker, however, it’s also easy to accumulate an excessive number of unused images, containers, and data volumes that clutter the output and consume disk space.
Docker使将应用程序和服务包装在容器中变得容易,因此您可以在任何地方运行它们。 但是,当您使用Docker时,也很容易累积过多的未使用映像,容器和数据量,从而使输出混乱并占用磁盘空间。
Docker gives you all the tools you need to clean up your system from the command line. This cheat sheet-style guide provides a quick reference to commands that are useful for freeing disk space and keeping your system organized by removing unused Docker images, containers, and volumes.
Docker提供了从命令行清理系统所需的所有工具。 该备忘单样式指南提供了对命令的快速参考,这些命令对于通过删除未使用的Docker映像,容器和卷来释放磁盘空间和使系统井井有条。
How to Use This Guide:
如何使用本指南:
The command substitution syntax, command $(command)
, used in the commands is available in many popular shells such as bash, zsh, and Windows Powershell.
这些命令中使用的命令替换语法command $( command )
在许多流行的Shell中都可用,例如bash,zsh和Windows Powershell。
Docker provides a single command that will clean up any resources — images, containers, volumes, and networks — that are dangling (not associated with a container):
Docker提供了一个命令,该命令将清除悬空(不与容器关联)的所有资源(图像,容器,卷和网络):
To additionally remove any stopped containers and all unused images (not just dangling images), add the -a
flag to the command:
要另外删除所有停止的容器和所有未使用的映像(不仅仅是悬空的映像),请在命令中添加-a
标志:
Use the docker images
command with the -a
flag to locate the ID of the images you want to remove. This will show you every image, including intermediate image layers. When you’ve located the images you want to delete, you can pass their ID or tag to docker rmi
:
将docker images
命令与-a
标志一起使用,以找到要删除的映像的ID。 这将显示每个图像,包括中间图像层。 找到要删除的图像后,可以将其ID或标签传递给docker rmi
:
List:
清单:
Remove:
去掉:
docker rmi Image Image
docker rmi 图片 图片
Docker images consist of multiple layers. Dangling images are layers that have no relationship to any tagged images. They no longer serve a purpose and consume disk space. They can be located by adding the filter flag, -f
with a value of dangling=true
to the docker images
command. When you’re sure you want to delete them, you can use the docker image prune
command:
Docker映像由多层组成。 悬空图像是与任何标记图像都没有关系的图层。 它们不再用于目的并且消耗磁盘空间。 可以通过向docker images
命令添加值为dangling=true
的过滤器标志-f
来定位它们。 确定要删除它们时,可以使用docker image prune
命令:
Note: If you build an image without tagging it, the image will appear on the list of dangling images because it has no association with a tagged image. You can avoid this situation by when you build, and you can retroactively tag an images with the command.
注意:如果生成的图像没有标记,则该图像将显示在悬空图像列表中,因为它与标记的图像没有关联。 您可以通过在构建时来避免这种情况,并且可以使用命令追溯性标记图像。
List:
清单:
Remove:
去掉:
You can find all the images that match a pattern using a combination of docker images
and . Once you’re satisfied, you can delete them by using awk
to pass the IDs to docker rmi
. Note that these utilities are not supplied by Docker and are not necessarily available on all systems:
您可以使用docker images
和的组合找到所有与模式匹配的docker images
。 满意后,您可以使用awk
将ID传递给docker rmi
来删除它们。 请注意,这些实用程序不是由Docker提供的,不一定在所有系统上都可用:
List:
清单:
docker images -a | grep "pattern"
泊坞窗图像-a | grep“ 模式 ”
Remove:
去掉:
docker images -a | grep "pattern" | awk '{print $3}' | xargs docker rmi
泊坞窗图像-a | grep“ 模式 ” | awk'{print $ 3}'| xargs docker rmi
All the Docker images on a system can be listed by adding -a
to the docker images
command. Once you’re sure you want to delete them all, you can add the -q
flag to pass the Image ID to docker rmi
:
通过在docker images
命令中添加-a
可以列出系统上的所有Docker映像。 确定要全部删除后,可以添加-q
标志以将映像ID传递给docker rmi
:
List:
清单:
Remove:
去掉:
Use the docker ps
command with the -a
flag to locate the name or ID of the containers you want to remove:
将docker ps
命令与-a
标志一起使用,以找到要删除的容器的名称或ID:
List:
清单:
Remove:
去掉:
docker rm ID_or_Name ID_or_Name
docker rm ID_or_Name ID_or_Name
If you know when you’re creating a container that you won’t want to keep it around once you’re done, you can run docker run --rm
to automatically delete it when it exits.
如果您知道创建容器时不想再保留它,则可以docker run --rm
以在退出时自动将其删除。
Run and Remove:
运行并删除:
docker run --rm image_name
泊坞窗运行--rm image_name
You can locate containers using docker ps -a
and filter them by their status: created, restarting, running, paused, or exited. To review the list of exited containers, use the -f
flag to filter based on status. When you’ve verified you want to remove those containers, using -q
to pass the IDs to the docker rm
command.
您可以使用docker ps -a
查找容器,并按其状态过滤容器:创建,重新启动,运行,暂停或退出。 要查看已退出容器的列表,请使用-f
标志基于状态进行过滤。 确认要删除这些容器后,请使用-q
将ID传递给docker rm
命令。
List:
清单:
Remove:
去掉:
Docker filters can be combined by repeating the filter flag with an additional value. This results in a list of containers that meet either condition. For example, if you want to delete all containers marked as either Created (a state which can result when you run a container with an invalid command) or Exited, you can use two filters:
可以通过重复过滤器标志和其他值来组合Docker过滤器。 这将产生一个满足任一条件的容器列表。 例如,如果要删除所有标记为Created (使用无效命令运行容器时可能导致的状态)或Exited的容器,则可以使用两个过滤器:
List:
清单:
Remove:
去掉:
You can find all the containers that match a pattern using a combination of docker ps
and . When you’re satisfied that you have the list you want to delete, you can use awk
and xargs
to supply the ID to docker rm
. Note that these utilities are not supplied by Docker and not necessarily available on all systems:
您可以结合使用docker ps
和找到与模式匹配的所有容器。 当您对要删除的列表感到满意时,可以使用awk
和xargs
将ID提供给docker rm
。 请注意,这些实用程序不是由Docker提供的,不一定在所有系统上都可用:
List:
清单:
docker ps -a | grep "pattern”
泊坞窗ps -a | grep“ 模式 ”
Remove:
去掉:
docker ps -a | grep "pattern" | awk '{print $1}' | xargs docker rm
泊坞窗ps -a | grep“ 模式 ” | awk'{print $ 1}'| xargs docker rm
You can review the containers on your system with docker ps
. Adding the -a
flag will show all containers. When you’re sure you want to delete them, you can add the -q
flag to supply the IDs to the docker stop
and docker rm
commands:
您可以使用docker ps
查看系统上的容器。 添加-a
标志将显示所有容器。 确定要删除它们时,可以添加-q
标志以将ID提供给docker stop
和docker rm
命令:
List:
清单:
Remove:
去掉:
Use the docker volume ls
command to locate the volume name or names you wish to delete. Then you can remove one or more volumes with the docker volume rm
command:
使用docker volume ls
命令找到要删除的卷名。 然后,您可以使用docker volume rm
命令删除一个或多个卷:
List:
清单:
Remove:
去掉:
docker volume rm volume_name volume_name
码头工人卷rm volume_name volume_name
Since the point of volumes is to exist independent from containers, when a container is removed, a volume is not automatically removed at the same time. When a volume exists and is no longer connected to any containers, it’s called a dangling volume. To locate them to confirm you want to remove them, you can use the docker volume ls
command with a filter to limit the results to dangling volumes. When you’re satisfied with the list, you can remove them all with docker volume prune
:
由于卷的位置要独立于容器而存在,因此,在删除容器时,不会同时自动删除卷。 当一个卷存在并且不再连接到任何容器时,称为悬挂卷。 要找到它们以确认要删除它们,可以将docker volume ls
命令与过滤器一起使用,以将结果限制为悬空的体积。 对列表满意后,可以使用docker volume prune
将其全部删除:
List:
清单:
Remove:
去掉:
If you created an unnamed volume, it can be deleted at the same time as the container with the -v
flag. Note that this only works with unnamed volumes. When the container is successfully removed, its ID is displayed. Note that no reference is made to the removal of the volume. If it is unnamed, it is silently removed from the system. If it is named, it silently stays present.
如果创建了未命名的卷,则可以使用-v
标志将其与容器同时删除。 请注意,这仅适用于未命名的卷。 成功删除容器后,将显示其ID。 请注意,未提及删除卷。 如果未命名,则将其从系统中静默删除。 如果已命名,它会静默地存在。
Remove:
去掉:
docker rm -v container_name
泊坞窗rm -v container_name
This guide covers some of the common commands used to remove images, containers, and volumes with Docker. There are many other combinations and flags that can be used with each. For a comprehensive guide to what’s available, see the Docker documentation for , , and . If there are common cleanup tasks you’d like to see in the guide, please ask or make suggestions in the comments.
本指南介绍了一些用于使用Docker删除映像,容器和卷的常用命令。 每个都有许多其他组合和标志。 有关可用功能的全面指南,请参阅docker文档,有关 , , 和 。 如果您想在指南中看到一些常见的清理任务,请在评论中提出要求或提出建议。
翻译自:
docker数据卷容器卷
转载地址:http://uvegb.baihongyu.com/