关于 DreamCat

主题名称:DreamCat | 版本:3.0.240224

主题开发:HanFengA7 | CornWorld

Designed by HanFengA7 Power by Typecho

Copyright © 2015-2024 by LychApe All rights reserved!

menu
refresh

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

作者: ciaoℒy

时间:

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


#本文链接:https://blog.chaol.top/archives/69.html
#本文采用 CC BY-NC-SA 4.0 协议进行许可
#如无特别声明,该文章均为 ciaoℒy 原创,转载请遵循 署名-非商业性使用 4.0 国际(CC BY-NC 4.0)协议,即转载请注明文章来源。
#最后编辑时间为: 2023 年 09 月 02 日
none

create 添加新评论


account_circle
email
language
textsms


assessment 仅有一条评论
  1. 2023-07-30 10:37

    难得见你英文写博客




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