If you’re running Docker on Windows, you may eventually find that the default drive (usually C:) begins to run low on space. One effective solution is to relocate your Docker volumes to a different drive. In this blog post, we’ll walk you through how to move the Docker volumes folder from its default location to another drive using a symbolic link (junction). This approach avoids making extensive changes to Docker’s configuration while effectively shifting your data to a more spacious location.
Why Move Docker Volumes?
Docker volumes are used to persist data for your containers. Over time, especially if you’re working with multiple or data-intensive containers, these volumes can consume a significant amount of disk space. By moving the volumes to another drive:
- Free up space on your system drive: Keep your OS drive clean and responsive.
- Improve performance: Distribute I/O load if your alternative drive is optimized for storage performance.
- Simplify management: Using a junction means you don’t have to reconfigure Docker; it simply follows the symbolic link.
Step-by-Step Guide
1. Stop Docker Desktop
Before making any changes, ensure Docker Desktop is not running. This avoids any potential conflicts or data corruption during the move.
- Tip: Right-click the Docker icon in the system tray and select Quit Docker Desktop.
2. Move the Volumes Folder
Next, move the volumes folder from its default location to your desired drive.
- Default Location: C:\Users\Anirudha\AppData\Local\Docker\wsl\disk\docker_data.vhdx
- Example New Location:
D:\DockerVolumes
\docker_data.vhdx
You can use File Explorer or a command line move command. Make sure that the new location exists and that you have proper permissions to write there.
3. Create a Junction Point
After moving the folder, you’ll need to create a symbolic link (junction) so that Docker can still find the volumes in its expected location.
- Rename the old file: Before creating the symlink, rename the old docker_data.vhdx to something else so that it does not create any conflict.
- Open an Elevated Command Prompt:
- Press Win + X and choose Command Prompt (Admin).
- Run the Following Command:
mklink "C:\Users\Anirudha\AppData\Local\Docker\wsl\disk\docker_data.vhdx" "D:\DockerData\docker_data.vhdx"
- This command creates a junction that points the original volumes folder location to the new one on drive D:. Docker will continue to work seamlessly as it accesses volumes through this link.
4. Restart Docker Desktop
Now that the symbolic link is in place, restart Docker Desktop. It will automatically follow the junction, storing and accessing volumes from the new location on your alternate drive.
- Tip: Verify that your containers can read and write data as expected after the change.
Additional Tips & Troubleshooting
- Back Up Your Data: Before moving critical data, always ensure you have a backup in case something unexpected occurs.
- Permission Issues: If you run into permission errors, double-check that the new folder (
D:\DockerVolumes
) has the proper permissions set for Docker to access it. - Reverting the Change: If you encounter problems, you can delete the junction and move the folder back to its original location.
Feel free to share your experiences or ask questions in the comments below. Happy Dockering!
just found this guide very helpful was trying to do this for a long time couldn’t find one until today, thanks tho.
btw the command to create the symlink is not complete.
Hi Anirudha,
Thanks for this clear guide! moving my Docker volumes worked perfectly once I sorted out the command. However, I ran into a couple of issues that might help future readers:
1. Your post says to run
“`
“C:\Users\Anirudha\AppData\Local\Docker\wsl\disk\docker_data.vhdx” “D:\DockerData\docker_data.vhdx”
“`
but doesn’t explain how to invoke mklink or which shell to use.
2. In PowerShell I got:
“`
PS C:\Users\Administrador> mklink “C:\Users\Administrador\AppData\Local\Docker\wsl\disk\docker_data.vhdx” “D:\AppData\Docker\docker_data.vhdx”
mklink : The term ‘mklink’ is not recognized as the name of a cmdlet
“`
and then:
“`
PS C:\Users\Administrador> “C:\Users\Administrador\AppData\Local\Docker\wsl\disk\docker_data.vhdx” “D:\AppData\Docker\docker_data.vhdx”
Token “D:\AppData\Docker\docker_data.vhdx” unexpected in expression or statement.
“`
3. The fix was to open **Command Prompt (Admin)**, not PowerShell, and run the actual mklink command:
“`
mklink “C:\Users\Administrador\AppData\Local\Docker\wsl\disk\docker_data.vhdx” “D:\AppData\Docker\docker_data.vhdx”
“`
Could you please update the post to specify that you need to open CMD as administrator and include the mklink prefix? That would save others a bit of head-scratching. Thanks again for the helpful tutorial!
Thank you. Updated the article. My mistake I didn’t proof read it properly.