How To Change Docker Data Path On Windows 10
It provides all the steps required to change the images and containers path of the Docker Desktop on Windows 10.
The default path of Docker Desktop data is C:\ProgramData\Docker. The main issue with Docker in C drive is the space limitation. We might have allocated low space to C drive while installing Windows Operation System. Also, the Docker images and containers need a good amount of space on the disk. In such cases, we have to move the Docker images and containers to another drive having sufficient space. This tutorial provides all the steps required to change the images and containers path of the Docker Desktop on Windows 10. The steps should be the same on other versions of the Windows Operating System.
Notes: In case you are using WSL 2 for Docker Desktop, you can skip to the section Configuring WSL 2 Virtual Disk location. You may also follow the Symlink approach as mentioned in the Approach C section. Also, make sure to take the required backups before starting the process in case of any failure in either of the approaches.
Approach A - Configure Data Root
Open the location C:\ProgramData\Docker\config and add daemon.json if it does not exist.
Stop Docker Desktop
Stop the Docker Desktop before making the changes.
Now update the daemon.json as shown below.
It will specify the path to store all the images, containers, and layers out of the C drive.
Start Docker Desktop
Now start the Docker Desktop after applying the changes.
We can also test the changes by issuing the below-mentioned command using PowerShell.
docker pull hello-world
It should create the files to the new location.
Approach B - Configure WSL 2 Data Location
Configuring WSL 2 Virtual Disk location
This step is specific for the Docker Desktop installation with WSL 2. The WSL 2 Docker Desktop Data Virtual Machine default location is %USERPROFILE%\AppData\Local\Docker\wsl\data\ext4.vhdx. You can follow the below-listed steps to relocate the docker data.
Step 1 - Shut down the Docker Desktop by right-clicking the Docker Tray Icon as shown in Fig 1.
Step 2 - Relocate the docker-desktop-data virtual machine disk image using the below-mentioned commands as shown in Fig 2.
wsl --export docker-desktop-data docker-desktop-data.tar
wsl --unregister docker-desktop-data
wsl --import docker-desktop-data e:\docker\wsl\data docker-desktop-data.tar --version 2
Step 3 - Delete %USERPROFILE%\docker-desktop-data.tar.
Step 4 - Start Docker Desktop. It should start using the new location of WSL data.
Approach C - Configure Symlinks
In this approach, we will simply stop the Docker Desktop, move the space-eating directories to another drive having sufficient space, and finally creating symlinks.
Step 1 - Stop Docker Desktop.
Step 2 - Relocate the existing directories %USERPROFILE%\AppData\Local\Docker and C:\ProgramData\Docker to new directories. For example - move %USERPROFILE%\AppData\Local\Docker to E:\Docker\AppData and C:\ProgramData\Docker to E:\Docker\ProgramData. Make sure that you completely remove the existing directories from the C drive before creating the symlinks as shown below.
# Link AppData - Replace youruser with actual user
mklink /j "C:\Users\youruser\AppData\Local\Docker" "E:\Docker\AppData"
# Link ProgramData
mklink /j "C:\ProgramData\Docker" "E:\Docker\ProgramData"
Step 3 - Now start the Docker Desktop. It should start the Docker Engine using the new directories.
This tutorial provided all the steps required to specify the Docker Desktop location to store the containers, images, and volumes. It also provided the steps to relocate the WSL docker-desktop-data virtual machine disk image to a new location for Docker Desktop installed with WSL 2.