If you have read my post (https://blog.takurohuang.com/2023/07/03/install-wsl2-to-other-disk-drive-and-intro-basic-commands-for-wsl/), the subsequent step would likely involve installing Docker on your desktop. However, you may encounter a similar challenge in installing Docker on a drive other than the default C: drive.
If so, this post will be an answer for you.
Install Docker Desktop:
- Download Docker desktop from Docker official site (https://www.docker.com/products/docker-desktop/).
- To install Docker Desktop using the command line and specify a custom installation directory, you can follow these refined steps:
- Open a terminal or command prompt.
- Navigate to the directory where the “Docker Desktop Installer.exe” file is located using the
cd
command. For examplecd C:\Path\To\Installer\Folder
- Execute the following command to start the Docker Desktop installation with the specified installation directory
start /w "" "Docker Desktop Installer.exe" install --accept-license --installation-dir=D:\Docker\
ReplaceD:\Docker\
with the desired installation directory path on your system.
- Execute Docker Desktop application to see if everything works.
- Open another terminal or command prompt and enter
wsl -l -v
. You should see like this:
docker-desktop is the application, docker-desktop-data is where the images will be stored. If you followed the instruction correctly, then docker-desktop should be installed at where you have indicated.
Move docker-desktop-data to other drive
Despite choosing a different installation directory, the docker-desktop-data folder, which contains Docker’s data including images, containers, and other persistent information, will still be located on the system drive (typically C: drive) by default. This can result in rapid growth of the folder, particularly when working with multiple images. Therefore, next step is moving docker-desktop-data to other drive.
- Open a terminal and enter
wsl --shutdown
to stop all subsystems. - Export docker-desktop-data to somewhere by entering
wsl --export docker-desktop-data D:\Docker-Data\docker-desktop-data.tar
. You can changeD:\Docker-Data\docker-desktop-data.tar
accordingly. Just make sure that the path is existing in your machine. - Unregister docker-desktop-data by entering
wsl --unregister docker-desktop-data
. This command will also delete the original ext4.vhdx in defaut drive (typically C: drive) - Import docker-desktop-data again and assign a path to indicate where it should be store. You can do it via
wsl --import docker-desktop-data D:\Docker\data D:\Docker-Data\docker-desktop-data.tar --version 2
. ReplaceD:\Docker\data
with the appropriate path where you want to store the “docker-desktop-data” folder. Additionally, ensure that the pathD:\Docker-Data\docker-desktop-data.tar
matches the location where you have stored the exported file from step 2. - Enter
wsl -v -l
to see if you can still see docker-desktop-data and docker-desktop.
搶先發佈留言