博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
docker数据卷容器卷_如何删除Docker映像,容器和卷
阅读量:2507 次
发布时间:2019-05-11

本文共 10093 字,大约阅读时间需要 33 分钟。

docker数据卷容器卷

Docker备忘单 (A Docker Cheat Sheet)

介绍 (Introduction)

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:

如何使用本指南:

  • This guide is in cheat sheet format with self-contained command-line snippets

    本指南采用备忘单格式,包含独立的命令行摘要
  • Jump to any section that is relevant to the task you are trying to complete.

    跳至与您要完成的任务有关的任何部分。

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。

清除所有未使用或悬挂的图像,容器,卷和网络 (Purging All Unused or Dangling Images, Containers, Volumes, and Networks)

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提供了一个命令,该命令将清除悬空(不与容器关联)的所有资源(图像,容器,卷和网络):

  • docker system prune

    码头工人系统修剪

To additionally remove any stopped containers and all unused images (not just dangling images), add the -a flag to the command:

要另外删除所有停止的容器和所有未使用的映像(不仅仅是悬空的映像),请在命令中添加-a标志:

  • docker system prune -a

    码头工人系统修剪-a

删除Docker映像 (Removing Docker Images)

删除一个或多个特定图像 (Remove one or more specific images)

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:

清单:

  • docker images -a

    码头工人图像-a

Remove:

去掉:

  • docker rmi Image Image

    docker rmi 图片 图片

删除悬空的图像 (Remove dangling images)

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:

清单:

  • docker images -f dangling=true

    码头工人图像-f dangling = true

Remove:

去掉:

  • docker image prune

    docker镜像修剪

根据图案去除图像 (Removing images according to a pattern)

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

删除所有图片 (Remove all images)

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:

清单:

  • docker images -a

    码头工人图像-a

Remove:

去掉:

  • docker rmi $(docker images -a -q)

    泊坞窗rmi $(泊坞窗图像-a -q)

取出容器 (Removing Containers)

移除一个或多个特定容器 (Remove one or more specific containers)

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:

清单:

  • docker ps -a

    码头工人ps -a

Remove:

去掉:

  • docker rm ID_or_Name ID_or_Name

    docker rm ID_or_Name ID_or_Name

退出时取出容器 (Remove a container upon exit)

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

删除所有退出的容器 (Remove all exited containers)

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:

清单:

  • docker ps -a -f status=exited

    docker ps -a -f status =退出

Remove:

去掉:

  • docker rm $(docker ps -a -f status=exited -q)

    docker rm $(docker ps -a -f status =退出-q)

使用多个过滤器取出容器 (Remove containers using more than one filter)

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:

清单:

  • docker ps -a -f status=exited -f status=created

    码头工人ps -a -f status = exited -f status = created

Remove:

去掉:

  • docker rm $(docker ps -a -f status=exited -f status=created -q)

    泊坞窗rm $(docker ps -a -f status = exited -f status = created -q)

根据模式取出容器 (Remove containers according to a pattern)

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和找到与模式匹配的所有容器。 当您对要删除的列表感到满意时,可以使用awkxargs将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

停止并取出所有容器 (Stop and remove all containers)

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 stopdocker rm命令:

List:

清单:

  • docker ps -a

    码头工人ps -a

Remove:

去掉:

  • docker stop $(docker ps -a -q)

    码头工人停止$(docker ps -a -q)
  • docker rm $(docker ps -a -q)

    泊坞窗rm $(docker ps -a -q)

删除卷 (Removing Volumes)

删除一个或多个特定的卷-Docker 1.9及更高版本 (Remove one or more specific volumes - Docker 1.9 and later)

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:

清单:

  • docker volume ls

    docker卷ls

Remove:

去掉:

  • docker volume rm volume_name volume_name

    码头工人卷rm volume_name volume_name

删除悬空的卷-Docker 1.9及更高版本 (Remove dangling volumes - Docker 1.9 and later)

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:

清单:

  • docker volume ls -f dangling=true

    码头工人卷ls -f dangling = true

Remove:

去掉:

  • docker volume prune

    码头工人修剪

取出容器及其体积 (Remove a container and its volume)

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

结论 (Conclusion)

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/

你可能感兴趣的文章
kafka web端管理工具 kafka-manager【转发】
查看>>
获取控制台窗口句柄GetConsoleWindow
查看>>
Linux下Qt+CUDA调试并运行
查看>>
51nod 1197 字符串的数量 V2(矩阵快速幂+数论?)
查看>>
OKMX6Q在ltib生成的rootfs基础上制作带QT库的根文件系统
查看>>
zabbix
查看>>
多线程基础
查看>>
完美解决 error C2220: warning treated as error - no ‘object’ file generated
查看>>
使用SQL*PLUS,构建完美excel或html输出
查看>>
SQL Server数据库笔记
查看>>
X-Forwarded-For伪造及防御
查看>>
android系统平台显示驱动开发简要:LCD驱动调试篇『四』
查看>>
Android 高仿微信头像截取 打造不一样的自定义控件
查看>>
Jenkins的初级应用(1)-Publish Over SSH
查看>>
【原】RDD专题
查看>>
第三周——构建一个简单的Linux系统MenuOS
查看>>
Docker 的两类存储资源 - 每天5分钟玩转 Docker 容器技术(38)
查看>>
Codeforces 257D
查看>>
常用的20个强大的 Sublime Text 插件
查看>>
ajaxfileupload.js在IE中的支持问题
查看>>