With the passage of time running Docker in development, we tend to accumulate a lot of unused images. Sometimes for testing, research or just trying out fun new stuff. It's always cool to run new software in containers, lights up new possibilities for those of us interested in constantly learning new technologies. Downside is a lot of precious SSD memory occupied with rarely used or unused images, the worse thing is we hardly notice. But the guys at Docker Inc. have done a great task by keeping a track of all things Docker.
随着在开发中运行Docker的时间的流逝,我们倾向于累积许多未使用的映像。 有时用于测试,研究或只是尝试有趣的新事物。 在容器中运行新软件总是很酷,对于那些有兴趣不断学习新技术的人们来说,这提供了新的可能性。 缺点是大量珍贵的SSD内存占用了很少使用或未使用的映像,更糟糕的是我们几乎没有注意到。 但是,通过跟踪Docker的所有事情,Docker Inc.的家伙们已经完成了一项伟大的任务。
Say hello to the system
command, part of the docker management commands and simply awesomeness. The system
command provides info from disk usage to system-wide information, ain’t that cool.
向system
命令打个招呼,这是docker管理命令的一部分,简直太棒了。 system
命令提供从磁盘使用情况到系统范围信息的信息,这并不酷。
使用 df
命令的 磁盘使用情况 : (Disk usage using df
command:)
$ docker system df
Returns something like this,
返回类似这样的内容,
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 35 6 8.332GB 7.364GB (88%)
Containers 12 12 417.6MB 0B (0%)
Local Volumes 67 2 2.828GB 2.828GB (100%)
Build Cache 0B 0B
Notice the Reclaimable
this is the size you can recover, it is calculated by subtracting the size of active images from the size of total images.
注意, Reclaimable
,这是可以恢复的大小,它是通过从总的图像的大小减去主动图像的大小来计算。
Real time events using events
command:
使用 events
命令 实时 events
:
$ docker system events
Returns the list of real time events from the server, based on Docker object types.
根据Docker对象类型,从服务器返回实时事件列表。
Formatting output
格式化输出
--format 'Type={{.Type}} Status={{.Status}} ID={{.ID}}'
or simply format the output as JSON
或简单地将输出格式化为JSON
$ docker system events --format '{{json .}}'
System-wide info using info
command:
使用 info
命令的 系统范围信息 :
Another cool command to get all the system related information is the info
command. You will be amazed to see the amount of info you can get.
获取所有与系统相关的信息的另一个很酷的命令是info
命令。 您会惊讶地看到您可以获得的信息量。
$ docker system info
Remove unused data using prune
command:
使用 prune
命令 删除未使用的数据 :
Now that we have all the info we need, its cleanup time, but beware against using this command half asleep.
现在,我们有了所需的所有信息,清理时间,但是请注意不要半睡着使用此命令。
$ 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]
Further we can remove exactly what we want, using any of the following commands, feast you eyes ladies and gents.
此外,我们可以使用以下任何命令删除您想要的东西,让您大饱眼福。
$ docker system prune -a --volumes
$ docker image prune
$ docker container prune
$ docker volume prune
$ docker network prune
All of the above commands will prompt for confirmation, so wash your face with cold water or take a shot of Espresso before issuing any of these ;).
以上所有命令都会提示您进行确认,因此在发出这些命令之前,请用冷水洗脸或喝一杯意式浓缩咖啡;)。