[英]Why removing docker containers and images does not free up storage space on Windows? How to fix it?
Problem:问题:
As I download and run containers, they keep taking up more and more space.当我下载并运行容器时,它们会占用越来越多的空间。 I found suggestions for cleaning up unused containers and images and I did so.
我找到了清理未使用的容器和图像的建议,我这样做了。 Guess what?
你猜怎么着? They eat up even more disk space
他们吃掉了更多的磁盘空间
What I found so far:到目前为止我发现了什么:
It has to do with .docker\machine\machines\default\disk.vmdk
file.它与
.docker\machine\machines\default\disk.vmdk
文件有关。 It only gets bigger它只会变得更大
Log of disk.vmdk: disk.vmdk 的日志:
size (MB)
1. with 2 images 1,376
2. downloading a new image X ?
3. running X as Y 2,963
4. removing Y 2,963
5. removing X 3,106
6. removing all the images 3,126
The only fix I found so far was running docker-machine rm default
which removes the VM.到目前为止,我发现的唯一修复是运行
docker-machine rm default
来删除 VM。 The problem is that I have to download all the images again.问题是我必须再次下载所有图像。 There should be a better fix.
应该有更好的解决办法。 Can someone explain:
有人可以解释一下:
There are maintainance commands you can run on the more recent versions of Docker.您可以在较新版本的 Docker 上运行维护命令。 They will free up space used by stopped containers, dangling images and dangling volumes:
它们将释放被停止容器、悬空图像和悬空卷使用的空间:
docker container prune -f
docker image prune -f
docker volume prune -f
Maybe the images you are using, use volumes.也许您正在使用的图像,使用卷。 If they do then deleting the container doesn't do the trick.
如果他们这样做,那么删除容器并不能解决问题。 You must delete the volumes as well.
您还必须删除卷。 In order to do that you must specify the
-v
flag when deleting a container为此,您必须在删除容器时指定
-v
标志
docker rm -v <container name or container id>
Depending on your docker version you will have some more commands available.根据您的 docker 版本,您将有更多可用的命令。 Check this SO thread for more.
查看此SO 线程了解更多信息。 You can read more about orphaned volumes in this SO thread
您可以在此SO 线程中阅读有关孤立卷的更多信息
After deleting all the unwanted containers and images using the commands below:使用以下命令删除所有不需要的容器和图像后:
I couldn't see any disk space released.我看不到任何释放的磁盘空间。 I found out the disk space was released after I restarted my Docker desktop.
我发现重新启动 Docker 桌面后磁盘空间已释放。
On windows 10, this was a major issue, space was not freeing up, even after I ran docker system prune
I started noticing this when I found that every week;在 Windows 10 上,这是一个主要问题,空间没有释放,即使在我运行
docker system prune
之后,当我每周都发现时,我开始注意到这一点; my SSD was filling up every2 or 3 GB of space.我的 SSD 每 2 或 3 GB 空间就被填满了。
Try opening Docker Desktop, hitting the Troubleshoot icon at the top right of the UI, and then clicking "Clean / Purge data".
尝试打开 Docker 桌面,点击 UI 右上角的疑难解答图标,然后单击“清理/清除数据”。 This reclaimed the space for me.
这为我收回了空间。
Also see:另见:
If anyone is struggling with this problem on Ubuntu:如果有人在 Ubuntu 上遇到这个问题:
In my case pruning and removing using the docker command did not help much.就我而言,使用 docker 命令进行修剪和删除并没有多大帮助。
The issue was docker/overlay2
folder.问题是
docker/overlay2
文件夹。
febrin@laptop:/var/lib$ sudo du -sh docker/overlay2
361G docker/overlay2
I had to delete it manually.我不得不手动删除它。
On windows using wsl2 follow the below steps.在使用 wsl2 的 windows 上,请按照以下步骤操作。 Note that you will lose all the docker images and containers if you follow this.
请注意,如果您按照此操作,您将丢失所有 docker 图像和容器。 If you want to retain data(images and containers) then you can try the prune option mentioned by other people on this thread.
如果您想保留数据(图像和容器),那么您可以尝试此线程上其他人提到的修剪选项。
Locate the vhdx file where docker stores the data.找到 docker 存储数据的 vhdx 文件。 This is a virtual hard disk used by docker.
这是docker使用的虚拟硬盘。
"P:\Users\your-username\AppData\Local\Docker\wsl\data\ext4.vhdx"
In my case docker is using up about 27GB of disk space in this file.在我的例子中,docker 在这个文件中使用了大约 27GB 的磁盘空间。 Even after deleting all the images and container, docker is not releasing the free disk space back to OS.
即使在删除所有图像和容器之后,docker 也不会将可用磁盘空间释放回操作系统。
To reclaim the disk space, you have to try clean/purge data option from the GUI.要回收磁盘空间,您必须尝试从 GUI 中清除/清除数据选项。 When prompted for the data set name, select WSL 2. This should clean up and give back all the unused space.
当提示输入数据集名称时,select WSL 2。这应该清理并归还所有未使用的空间。
In case, the docker daemon doesn't start up or disk space is not reduced then the last option is to factory restore from docker desktop GUI like show below.如果 docker 守护程序未启动或磁盘空间未减少,则最后一个选项是从 docker 桌面 GUI 恢复出厂设置,如下所示。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.