Menu Home

Move Docker for Windows Hyper-V Disk VHDX to another drive

Been using Docker for Windows quite a lot lately.

Unfortunately running docker containers on windows is still not done natively, so we have to rely on a Linux Hyper-V Virtual Machine. This VM have a tendency to grow large quite fast if you work with many images, and yesterday I found myself running out of space on my C-drive due to that.

Luckily I thought I could just change the settings for the vhd location from the docker for windows settings to my other drive. But nope. That didn’t work. Then I tried to move the Hyper-V disk manually, and changing the path in Hyper-V, which just resulted in Docker for windows reprovisioning the Hyper-V machine to the C-drive again.

In the end, it turns out that this functionality is quite buggy, so the way I managed to move my disk was to close docker completely. And move the disk to my other drive E:\VirtualMachine\MobyLinuxVM.vhdx. When that is done you can edit
C:\Users\blasi\AppData\Roaming\Docker\settings.json and change the value of MobyVhdPathOverride to the new location of the VHDX E:\\VirtualMachine\\MobyLinuxVM.vhdx. When you restart the docker for windows service, it will pick up the change and change your Hyper-V configuration for you.

Categories: docker

Tagged as:

Simon J.K. Pedersen

2 replies

  1. Hello, I found your article helpful but a year later it seems like Docker has made this a bit easier. I’m running Docker version 19.03.5, build 633a0ea. In the Docker Desktop settings under resources there is a Docker Image Location setting with a Browse button where you can select a new parent folder for the images. Inside of the folder you select it were create a folder named DockerDesktop and it migrate the DockerDesktop.vhdx file to this new location as it does a restart. For your uses case you would be done. I was interested in migrating my docker images from a different workstation to a new one with an empty docker image file. After migrating my empty vhdx file using docker, I quite Docker Desktop and then in windows services I shut down Docker Desktop Service. I then copied over the vhdx file I had moved from my other computer and restarted the Docker Desktop Service and re launch the Docker Desktop application. When it came up I looked into the settings and saw that the Disk Image Space used had increased from just a few megs to 1.5GB. The original space remained set at 64GB, big enough to hold the space I was bringing in. I imagine if I was going to bring in a larger file I might have needed to increase that setting before hand. I now can execute a docker ps -a cmd in ps and see my images. Thanks for the good article as it gave me the info I needed to work this out.

  2. Don’t forget windows 10 knows the concept on symlinks too. Creating a symlink like you do in linux is might have saved you some time.
    $ mklink DockerDesktop.vhdx D:\docker\DockerDesktop.vhdx
    in cmd

Leave a Reply

Your email address will not be published. Required fields are marked *