在Windows 10 Home中使用WSL2时如何更改docker映像的位置? [英] How can I change the location of docker images when using WSL2 with Windows 10 Home?
问题描述
我刚刚升级到2020年5月Windows 10 Home,已激活WSL2 ,并安装了 Docker桌面。
I've just upgraded to Windows 10 Home May 2020, activated WSL2, and installed Docker Desktop.
WSL2必须安装在我的系统磁盘中,该磁盘是小型SSD。我不想用docker图片填充它。如何更改docker映像路径?我想在大型Windows文件系统中使用路径。
WSL2 must be installed in my system disk, which is a small SSD. I don't want to fill it with docker images. How do I change the docker images path? I'd like to use a path in my big Windows filesystem.
图片位置有些令人困惑。我相信它在 / mnt / wsl / docker-desktop-data /
中。
The image location is somewhat confusing. I believe it is in /mnt/wsl/docker-desktop-data/
.
如何更改Docker映像的目录在WSL2中?我可以更改Docker配置以选择 / mnt / d
内的路径,还是通过Docker数据目录从/ mnt / d挂载路径?
How do I change the directory of docker images inside WSL2? May I change docker configuration to select a path inside /mnt/d
, or mount a path from /mnt/d over docker data dirs?
推荐答案
WSL 2 docker-desktop-data vm磁盘映像通常位于:
%USERPROFILE%\AppData\Local\Docker\ \wsl\data\ext4.vhdx
The WSL 2 docker-desktop-data vm disk image would normally reside in: %USERPROFILE%\AppData\Local\Docker\wsl\data\ext4.vhdx
请遵循以下步骤将其重新定位到其他驱动器/目录,并保留所有现有的Docker数据(针对Docker Desktop 2.3.0.4测试(46911)) :
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):
首先,通过右键单击Docker Desktop图标关闭Docker桌面,然后选择退出Docker Desktop
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.
NAME STATE VERSION
* docker-desktop Stopped 2
docker-desktop-data Stopped 2
将docker-desktop-data导出到文件中
Export docker-desktop-data into a file
wsl --export docker-desktop-data "D:\Docker\wsl\data\docker-desktop-data.tar"
从wsl注销docker-desktop-data,请注意,此后,您的ext4.vhdx文件将被自动删除
Unregister docker-desktop-data from wsl, note that after this, your ext4.vhdx file would automatically be removed
wsl --unregister docker-desktop-data
将docker-desktop-data导入回wsl,但是现在ext4.vhdx将驻留在不同的驱动器/目录中:
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
再次启动Docker桌面,它应该可以工作
Start the Docker Desktop again and it should work
您可以删除 D:\Docker\wsl\data\docker-desktop-data.tar;文件(不是ext4.vhdx文件),如果在验证后一切对您来说看起来都很不错
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
这篇关于在Windows 10 Home中使用WSL2时如何更改docker映像的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!