时光流年 發表於 2025-6-28 00:00:00

Windows系统下装Docker至D盘/其他盘最新方法

<div id="navCategory"><h5 class="catalogue">目录</h5><ul class="first_class_ul"><li>前言</li><li>步骤</li><li>Windows Docker 配置镜像源的两种方法<ul class="second_class_ul"><li>一、简介</li><li>二、配置镜像源</li><ul class="third_class_ul"><li>2.1 通过 Docker-Desktop</li><li>2.2 修改 daemon.json 文件</li></ul></ul></li><li>总结<ul class="second_class_ul"></ul></li></ul></div><p class="maodian"></p><h2>前言</h2>
<p>Docker的默认安装路径为</p>
<div class="dxycode"><pre class="brush:bash;">C:\你的用户名\AppData\Local\Docker\wsl</pre></div>
<p>这样安装常常会导致C盘爆满。目前现有博客的安装方法往往不能把docker的container和image也装在非C盘。本博客旨在用最简单的方式,把Docker Deskstop的images和container装在D盘中。</p>
<p>安装前,请提前打开WSL2,</p>
<p class="maodian"></p><h2>步骤</h2>
<p><strong>1. 上官网下载Docker Desktop Installer.exe</strong></p>
<p style="text-align:center"><img style="max-width:100%!important;height:auto!important;"alt="" src="https://zhuji.jb51.net/uploads/allimg/20250626/2-2506261H205P3.png" /></p>
<p style="text-align:center"><img style="max-width:100%!important;height:auto!important;"alt="" src="https://zhuji.jb51.net/uploads/allimg/20250626/2-2506261H205450.png" /></p>
<p><strong>2. 以管理员身份打开Windows终端,并转到你下载文件的位置。</strong></p>
<p style="text-align:center"><img style="max-width:100%!important;height:auto!important;"alt="" src="https://zhuji.jb51.net/uploads/allimg/20250626/2-2506261H205361.jpg" /></p>
<p>输入:cd + 你Docker Desktop Installer.exe下载到的地址。比如,我本机的命令为:</p>
<div class="dxycode"><pre class="brush:bash;">cd C:\Users\ASUS\Downloads</pre></div>
<p style="text-align:center"><img style="max-width:100%!important;height:auto!important;"alt="" src="https://zhuji.jb51.net/uploads/allimg/20250626/2-2506261H205162.png" /></p>
<p><strong>3. 在命令提示符内运行下面代码,并根据你的安装需求做出修改</strong>:</p>
<blockquote><p>start /w &ldquo;&rdquo; &ldquo;Docker Desktop Installer.exe&rdquo; install -accept-license --installation-dir=&ldquo;D:\Program Files\Docker&rdquo; --wsl-default-data-root=&ldquo;D:\Program Files\Docker\data&rdquo; --windows-containers-default-data-root=&ldquo;D:\Program Files\Docker&rdquo;</p></blockquote>
<div class="dxycode"><pre class="brush:bash;">start /w "" "Docker Desktop Installer.exe" install -accept-license --installation-dir="D:\Program Files\Docker" --wsl-default-data-root="D:\Program Files\Docker\data" --windows-containers-default-data-root="D:\\Program Files\\Docker"</pre></div>
<p>其中,D:\Program Files\Docker 是Docker Desktop 安装程序的安装目录,D:\Program Files\Docker\data是Docker存放是Docker 用于存储镜像、容器、卷等数据的目录。D:\Program Files\Docker,表示在 Windows 操作系统中,Docker 程序将被安装在 D 盘的 Program Files 文件夹内的一个名为 Docker 的子文件夹中,记得双斜杠。</p>
<p>在运行代码前,一定要提前手动创建好对应文件夹,不然会报错。</p>
<p><strong>4. 安装完成后,检查是否按要求更改image地址</strong></p>
<p style="text-align:center"><img style="max-width:100%!important;height:auto!important;"alt="" src="https://zhuji.jb51.net/uploads/allimg/20250626/2-2506261H20B24.png" /></p>
<p>可以看到,docker已经装在D盘目标目录内</p>
<p class="maodian"></p><h2>Windows Docker 配置镜像源的两种方法</h2>
<p class="maodian"></p><h3>一、简介</h3>
<p>Windows Docker 配置镜像源的两种方法。一是,通过 Docker Desktop 界面操作。二是,修改 daemon.json 配置文件。</p>
<p class="maodian"></p><h3>二、配置镜像源</h3>
<p class="maodian"></p><h4>2.1 通过 Docker-Desktop</h4>
<p>点击 设置,选择 Docker Engine ,添加下面源地址,然后并 重启 Docker 即可完成镜像源的配置。</p>
<div class="dxycode"><pre class="brush:bash;">,
"registry-mirrors": [
    "https://registry.cn-hangzhou.aliyuncs.com"
]</pre></div>
<p style="text-align:center"><img style="max-width:100%!important;height:auto!important;"alt="在这里插入图片描述" src="https://zhuji.jb51.net/uploads/allimg/20250626/2-2506261H206216.png" /></p>
<p style="text-align:center"><img style="max-width:100%!important;height:auto!important;"alt="在这里插入图片描述" src="https://zhuji.jb51.net/uploads/allimg/20250626/2-2506261H20I49.png" /></p>
<p class="maodian"></p><h4>2.2 修改 daemon.json 文件</h4>
<p>以我本机使用 Admin 账户为例,配置文件位于 C:\Users\Admin.docker\目录下的 daemon.json 文件。</p>
<p style="text-align:center"><img style="max-width:100%!important;height:auto!important;"alt="在这里插入图片描述" src="https://zhuji.jb51.net/uploads/allimg/20250626/2-2506261H211C2.png" /></p>
<p>打开 daemon.json 文件,添加下面<strong>源地址</strong>,然后并&nbsp;<strong>重启 Docker</strong>&nbsp;即可完成镜像源的配置。</p>
<div class="dxycode"><pre class="brush:json;">,
"registry-mirrors": [
    "https://registry.cn-hangzhou.aliyuncs.com"
]</pre></div>
<p style="text-align:center"><img style="max-width:100%!important;height:auto!important;"alt="在这里插入图片描述" src="https://zhuji.jb51.net/uploads/allimg/20250626/2-2506261H212448.png" /></p>
<p style="text-align:center"><img style="max-width:100%!important;height:auto!important;"alt="在这里插入图片描述" src="https://zhuji.jb51.net/uploads/allimg/20250626/2-2506261H20I49.png" /></p>
<p class="maodian"></p><h2>总结</h2>
<p>到此这篇关于Windows系统下装Docker至D盘/其他盘最新方法的文章就介绍到这了,更多相关Windows装Docker至D盘/其他盘内容请搜索琼殿技术社区以前的文章或继续浏览下面的相关文章希望大家以后多多支持琼殿技术社区!</p>
頁: [1]
查看完整版本: Windows系统下装Docker至D盘/其他盘最新方法