在 Windows 10 Home 的 WSL2 上使用 Docker Desktop 时,如何更改 docker 映像的位置? [英] How can I change the location of docker images when using Docker Desktop on WSL2 with Windows 10 Home?
问题描述
我刚刚升级到 Windows 10 Home 2020 年 5 月,激活了 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/
.
如何更改 WSL2 中 docker 镜像的目录?我可以更改 docker 配置以选择 /mnt/d
内的路径,或者将/mnt/d 中的路径挂载到 docker 数据目录上吗?
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%AppDataLocalDockerwsldataext4.vhdx
The WSL 2 docker-desktop-data vm disk image would normally reside in:
%USERPROFILE%AppDataLocalDockerwsldataext4.vhdx
按照以下步骤将其重新定位到其他驱动器/目录,并保留所有现有 docker 数据(针对 Docker Desktop 2.3.0.4 (46911) 进行测试,并在更新 3.1.0 (51484) 后继续工作):
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)):
首先,通过右键单击 Docker 桌面图标并选择退出 Docker 桌面来关闭 Docker 桌面
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
您应该可以看到,确保两者的状态都已停止.(wsl --shutdown
)
You should be able to see, make sure the STATE for both is Stopped.(wsl --shutdown
)
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:Dockerwsldatadocker-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 (so back it up first if you have important existing image/container):
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:Dockerwsldata" "D:Dockerwsldatadocker-desktop-data.tar" --version 2
再次启动 Docker 桌面,它应该可以工作了
Start the Docker Desktop again and it should work
如果一切正常,您可以删除 D:Dockerwsldatadocker-desktop-data.tar
文件(不是 ext4.vhdx
文件)验证后给你
You may delete the D:Dockerwsldatadocker-desktop-data.tar
file (NOT the ext4.vhdx
file) if everything looks good for you after verifying
这篇关于在 Windows 10 Home 的 WSL2 上使用 Docker Desktop 时,如何更改 docker 映像的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!