ciaoℒy
在Windows上更改Docker的数据存储位置

access_time
brush 3个字
whatshot 21 ℃
百度收录:百度已收录

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.

September 19, 2021

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

Add daemon.json

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.

Update daemon.json

Now update the daemon.json as shown below.

{  
 "data-root": "E:\\\\ProgramData\\\\Docker"  
}

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.

Test 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.

Fig 1

Step 2 - Relocate the docker-desktop-data virtual machine disk image using the below-mentioned commands as shown in Fig 2.

wsl --shutdown  

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

Fig 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.

Summary

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.


转载自 https://devops.tutorials24x7.com/blog/how-to-change-docker-data-path-on-windows-10

#如无特别声明,该文章均为 ciaoℒy 原创,转载请遵循 署名-非商业性使用 4.0 国际(CC BY-NC 4.0) 协议,即转载请注明文章来源。
#最后编辑时间为: 2022 年 11 月 14 日


create 添加新评论


account_circle
email
language
textsms





关于 DreamCat

主题名称:DreamCat | 版本:2.8.221001(LTS)

主题开发:HanFengA7 | TeddyNight | Dev-Leo | CornWorld | WhiteBearcn | DFFZMXJ

Designed by HanFengA7 Power by Typecho

Copyright © 2015-2022 by LychApe All rights reserved!

加我的QQ
加我的微博
加我的支付宝
加我的微信