当前位置:   article > 正文

Docker Desktop总是占用C盘空间的终极解决之道_docker desktop 2.3.0.4

docker desktop 2.3.0.4

原链接:How can I change the location of docker images when using Docker Desktop on WSL2 with Windows 10 Home? - Stack Overflowicon-default.png?t=L9C2https://stackoverflow.com/questions/62441307/how-can-i-change-the-location-of-docker-images-when-using-docker-desktop-on-wsl2

The WSL 2 docker-desktop-data vm disk image would normally reside in: %USERPROFILE%\AppData\Local\Docker\wsl\data\ext4.vhdx

Follow the following to relocate it to other drive/directory, with all existing docker data preserved (tested against Docker Desktop 2.3.0.4 (46911), and continued to work after updating the 3.1.0 (51484)):

First, shut down your docker desktop by right click on the Docker Desktop icon and select Quit Docker Desktop

Then, open your command prompt:

wsl --list -v

You should be able to see, make sure the STATE for both is Stopped.(wsl --shutdown)

  1. NAME STATE VERSION
  2. * docker-desktop Stopped 2
  3. docker-desktop-data Stopped 2

Export docker-desktop-data into a file

wsl --export docker-desktop-data "D:\Docker\wsl\data\docker-desktop-data.tar"

Unregister docker-desktop-data from wsl, note that after this, your ext4.vhdx file would automatically be removed (so back it up first if you have important existing image/container):

wsl --unregister docker-desktop-data

Import the docker-desktop-data back to wsl, but now the ext4.vhdx would reside in different drive/directory:

wsl --import docker-desktop-data "D:\Docker\wsl\data" "D:\Docker\wsl\data\docker-desktop-data.tar" --version 2

Start the Docker Desktop again and it should work

You may delete the D:\Docker\wsl\data\docker-desktop-data.tar file (NOT the ext4.vhdx file) if everything looks good for you after verifying

总结下来:

1. wsl --shutdown

2. 把wsl exports出去,这个步骤相当于把镜像文件保存到其他位置

3. 把tar文件import 到wsl内

中间可能会出现 “由于虚拟磁盘系统限制,无法完成请求的操作。虚拟硬盘文件必须是未压缩和未加密的文件,并且不能是稀疏文件”

请不要压缩你import 到的文件夹

举个例子,d:\docker\wsl\data 这个文件夹就不要做任何压缩了

同样的方法你也可以把Ubuntu 移动位置

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/天景科技苑/article/detail/956729
推荐阅读
相关标签
  

闽ICP备14008679号