Docker takes up a lot of space. Whenever we run containers, pull images, deploy applications, and build our own images, our disk space will be occupied a lot. If you are also troubled by this problem, let's take a look at how Docker uses disk space and how to reclaim it. The space occupied by docker can be viewed through the following command: $ docker system df
The final Let’s take a look at each of these types. Container disk usage Every time a container is created, some files and directories are created, for example:
Now we start from a completely clean system, assuming Docker has just been installed: First, we start an NGINX container: Now when you run the
There is no reclaimable space at this time because the container is running and the image is being used. Now, we create an empty file of 100MB inside the container: $ docker exec -ti www \ dd if=/dev/zero of=test.img bs=1024 count=0 seek=$[1024*100] Check the space again: You can see that the space occupied by the container has increased. Where is this file saved on the local machine? As mentioned above, it is stored in the read-write layer of the container. When the container is stopped, the space occupied by the container becomes reclaimable: How to recycle? Deleting a container deletes the space occupied by its associated read-write layer. You can also delete all stopped containers with one click: $ docker container prune After deleting the container, the image can also be recycled: The $ docker rm -f $(docker ps -aq) $ docker container rm -f $(docker container ls -aq) Mirror disk usage Some images are invisible:
The following command lists all pending images: $ docker image ls -f dangling=true Delete such images: $ docker image rm $(docker image ls -f dangling=true -q) or: $ docker image prune If you want to delete all images, you can use the following command: $ docker image rm $(docker image ls -q) Note that images that are being used by containers cannot be deleted. Disk usage of data volumes A data volume is a data storage outside of the container's own file system. For example, if the application in the container has the function of uploading pictures, the pictures cannot be saved inside the container after uploading, because the data inside the container will be deleted when the container dies. Therefore, these pictures must be saved outside the container, that is, in the data volume. For example, we run a MongoDB container for testing and import a lot of test data. This data is not in the container, but in the data volume, because the data volume is used in the MongoDB Dockerfile. After the test is completed, the MongoDB container is deleted, but the test data is still there and has not been deleted. Delete the data volume that is no longer in use: $ docker volume rm $(docker volume ls -q) or: $ docker volume prune Build Cache Disk Space Docker 18.09 introduced BuildKit, which improves the performance, security, storage management and other capabilities of the build process. To delete the build cache, you can use the command: $ docker builder prune One-click cleaning From the above description, we know that containers, images, and data volumes all provide the In fact, there is also a $ docker system prune It is a good habit to execute this command regularly. Translated from: https://medium.com/better-programming/docker-tips-clean-up-your-local-machine-35f370a01a78 The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: WeChat applet implements calculator function
>>: MySQL establishes efficient index example analysis
Detailed explanation of replace into example in m...
React multiple ways to get the value of the input...
There are some differences between filter and bac...
Moore's Law no longer applies Starting with F...
1. How to construct? Let's review the common ...
How to implement Mysql switching data storage dir...
Note 1: The entire background in the above pictur...
...It's like this, today I was going to make a...
<br />Original link: http://www.dudo.org/art...
This article shares 3 methods to achieve the spec...
Table of contents 1. Connect to Tencent Cloud Ser...
The page length in the project is about 2000px or...
The correspondence between tensorflow version and...
Execute the following command to report an error ...
1. Upper and lower list tags: <dl>..</dl...