Update Docker.md

重新绘制配图,补充容器的实现原理和 Kubernetes。
This commit is contained in:
CyC2018
2026-10-26 22:03:43 +08:00
parent 51e1f47a0e
commit c4fb20bc35
7 changed files with 268 additions and 5 deletions
+49
View File
@@ -0,0 +1,49 @@
<svg xmlns="http://www.w3.org/2000/svg" width="740" height="300" viewBox="0 0 740 300">
<style>
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
.b { font-weight: bold; }
.c { text-anchor: middle; }
.e { text-anchor: end; }
.sub { font-size: 11px; fill: #6E6E6E; }
.note { fill: #C0605A; }
.ok { fill: #6A9F68; }
.mono { font-family: Menlo, Consolas, monospace; }
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
.red { stroke: #C0605A; marker-end: url(#r); }
.green { stroke: #6A9F68; marker-end: url(#g); }
.dash { stroke-dasharray: 5 4; }
.line { stroke: #555; stroke-width: 1.1; fill: none; }
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
.shadow { fill: #DADADA; }
</style>
<defs>
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
</marker>
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
</marker>
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
</marker>
</defs>
<rect width="100%" height="100%" fill="#FFFFFF"/>
<text x="370" y="28" class="title">镜像分层与容器的可写层</text>
<rect x="60" y="56" width="380" height="36" rx="6" fill="#E6E3FA" stroke="#B8B0DE"/>
<text x="250" y="78.5" class="c sub">容器的可写层:运行时的修改都写在这里</text>
<rect x="60" y="100" width="380" height="36" rx="6" fill="#C6E4FB" stroke="#7FB2D6"/>
<text x="250" y="122.5" class="c sub">RUN pip install flask</text>
<rect x="60" y="144" width="380" height="36" rx="6" fill="#C6E4FB" stroke="#7FB2D6"/>
<text x="250" y="166.5" class="c sub">COPY app.py /app/</text>
<rect x="60" y="188" width="380" height="36" rx="6" fill="#EAE9E7" stroke="#BFBEBA"/>
<text x="250" y="210.5" class="c sub">FROM python:3.12-slim(基础镜像的多层)</text>
<text x="460" y="82" class="sub">可读写,容器删除后就没有了</text>
<path d="M452,108 q10,0 10,10 V220 q0,10 -10,10" class="line"/>
<text x="476" y="172" class="sub b" style="fill:#444">镜像的只读层</text>
<text x="476" y="190" class="sub">Dockerfile 的每条指令生成一层,</text>
<text x="476" y="206" class="sub">多个镜像共享相同的层</text>
<text x="30" y="262" class="sub">容器修改镜像中的文件时,先把文件复制到可写层再修改(写时复制),只读层不变,所以同一个镜像可以启动多个容器。</text>
<text x="30" y="280" class="sub">Dockerfile 中把变化少的指令放在前面,修改代码后重新构建时前面的层可以直接复用缓存。</text>
</svg>

After

Width:  |  Height:  |  Size: 3.0 KiB

+70
View File
@@ -0,0 +1,70 @@
<svg xmlns="http://www.w3.org/2000/svg" width="760" height="330" viewBox="0 0 760 330">
<style>
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
.b { font-weight: bold; }
.c { text-anchor: middle; }
.e { text-anchor: end; }
.sub { font-size: 11px; fill: #6E6E6E; }
.note { fill: #C0605A; }
.ok { fill: #6A9F68; }
.mono { font-family: Menlo, Consolas, monospace; }
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
.red { stroke: #C0605A; marker-end: url(#r); }
.green { stroke: #6A9F68; marker-end: url(#g); }
.dash { stroke-dasharray: 5 4; }
.line { stroke: #555; stroke-width: 1.1; fill: none; }
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
.shadow { fill: #DADADA; }
</style>
<defs>
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
</marker>
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
</marker>
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
</marker>
</defs>
<rect width="100%" height="100%" fill="#FFFFFF"/>
<text x="380" y="28" class="title">虚拟机与容器</text>
<text x="190" y="56" class="c b">虚拟机</text>
<rect x="40" y="66" width="145" height="30" rx="6" fill="#C6E4FB" stroke="#7FB2D6"/>
<text x="112.5" y="85.5" class="c sub">App A</text>
<rect x="195" y="66" width="145" height="30" rx="6" fill="#C6E4FB" stroke="#7FB2D6"/>
<text x="267.5" y="85.5" class="c sub">App B</text>
<rect x="40" y="102" width="145" height="30" rx="6" fill="#C6E4FB" stroke="#7FB2D6"/>
<text x="112.5" y="121.5" class="c sub">依赖库</text>
<rect x="195" y="102" width="145" height="30" rx="6" fill="#C6E4FB" stroke="#7FB2D6"/>
<text x="267.5" y="121.5" class="c sub">依赖库</text>
<rect x="40" y="138" width="145" height="30" rx="6" fill="#E6E3FA" stroke="#B8B0DE"/>
<text x="112.5" y="157.5" class="c sub">客户机 OS</text>
<rect x="195" y="138" width="145" height="30" rx="6" fill="#E6E3FA" stroke="#B8B0DE"/>
<text x="267.5" y="157.5" class="c sub">客户机 OS</text>
<rect x="40" y="174" width="300" height="30" rx="6" fill="#EAE9E7" stroke="#BFBEBA"/>
<text x="190" y="193.5" class="c sub">Hypervisor</text>
<rect x="40" y="210" width="300" height="30" rx="6" fill="#EAE9E7" stroke="#BFBEBA"/>
<text x="190" y="229.5" class="c sub">宿主机 OS</text>
<rect x="40" y="246" width="300" height="30" rx="6" fill="#EAE9E7" stroke="#BFBEBA"/>
<text x="190" y="265.5" class="c sub">服务器</text>
<text x="560" y="56" class="c b">容器</text>
<rect x="410" y="66" width="145" height="30" rx="6" fill="#C6E4FB" stroke="#7FB2D6"/>
<text x="482.5" y="85.5" class="c sub">App A</text>
<rect x="565" y="66" width="145" height="30" rx="6" fill="#C6E4FB" stroke="#7FB2D6"/>
<text x="637.5" y="85.5" class="c sub">App B</text>
<rect x="410" y="102" width="145" height="30" rx="6" fill="#C6E4FB" stroke="#7FB2D6"/>
<text x="482.5" y="121.5" class="c sub">依赖库</text>
<rect x="565" y="102" width="145" height="30" rx="6" fill="#C6E4FB" stroke="#7FB2D6"/>
<text x="637.5" y="121.5" class="c sub">依赖库</text>
<rect x="410" y="138" width="300" height="30" rx="6" fill="#C6ECE9" stroke="#7DBCB7"/>
<text x="560" y="157.5" class="c sub">容器运行时(Docker Engine)</text>
<rect x="410" y="174" width="300" height="30" rx="6" fill="#EAE9E7" stroke="#BFBEBA"/>
<text x="560" y="193.5" class="c sub">宿主机 OS(共享一个内核)</text>
<rect x="410" y="210" width="300" height="30" rx="6" fill="#EAE9E7" stroke="#BFBEBA"/>
<text x="560" y="229.5" class="c sub">服务器</text>
<text x="30" y="296" class="sub">虚拟机为每个应用运行一个完整的操作系统,启动要几十秒、占用 GB 级内存;容器只是宿主机上隔离的进程,</text>
<text x="30" y="314" class="sub">共享宿主机的内核,启动通常在 1 秒以内。代价是隔离性不如虚拟机,也不能在 Linux 宿主机上直接运行 Windows 容器。</text>
</svg>

After

Width:  |  Height:  |  Size: 4.4 KiB

+61
View File
@@ -0,0 +1,61 @@
<svg xmlns="http://www.w3.org/2000/svg" width="740" height="250" viewBox="0 0 740 250">
<style>
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
.b { font-weight: bold; }
.c { text-anchor: middle; }
.e { text-anchor: end; }
.sub { font-size: 11px; fill: #6E6E6E; }
.note { fill: #C0605A; }
.ok { fill: #6A9F68; }
.mono { font-family: Menlo, Consolas, monospace; }
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
.red { stroke: #C0605A; marker-end: url(#r); }
.green { stroke: #6A9F68; marker-end: url(#g); }
.dash { stroke-dasharray: 5 4; }
.line { stroke: #555; stroke-width: 1.1; fill: none; }
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
.shadow { fill: #DADADA; }
</style>
<defs>
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
</marker>
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
</marker>
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
</marker>
</defs>
<rect width="100%" height="100%" fill="#FFFFFF"/>
<text x="370" y="28" class="title">容器:把应用和依赖打包在一起</text>
<rect x="40" y="56" width="200" height="130" rx="6" fill="#C6E4FB" stroke="#7FB2D6"/>
<text x="140" y="76" class="c sub b" style="fill:#444">容器</text>
<rect x="60" y="86" width="160" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
<text x="140" y="103" class="c sub" style="fill:#444">订单服务</text>
<rect x="60" y="116" width="160" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
<text x="140" y="133" class="c sub" style="fill:#444">JDK 21</text>
<rect x="60" y="146" width="160" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
<text x="140" y="163" class="c sub" style="fill:#444">Debian</text>
<rect x="270" y="56" width="200" height="130" rx="6" fill="#C6E4FB" stroke="#7FB2D6"/>
<text x="370" y="76" class="c sub b" style="fill:#444">容器</text>
<rect x="290" y="86" width="160" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
<text x="370" y="103" class="c sub" style="fill:#444">推荐服务</text>
<rect x="290" y="116" width="160" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
<text x="370" y="133" class="c sub" style="fill:#444">Python 3.12</text>
<rect x="290" y="146" width="160" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
<text x="370" y="163" class="c sub" style="fill:#444">Ubuntu</text>
<rect x="500" y="56" width="200" height="130" rx="6" fill="#C6E4FB" stroke="#7FB2D6"/>
<text x="600" y="76" class="c sub b" style="fill:#444">容器</text>
<rect x="520" y="86" width="160" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
<text x="600" y="103" class="c sub" style="fill:#444">网关</text>
<rect x="520" y="116" width="160" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
<text x="600" y="133" class="c sub" style="fill:#444">静态二进制</text>
<rect x="520" y="146" width="160" height="26" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
<text x="600" y="163" class="c sub" style="fill:#444">Alpine</text>
<rect x="40" y="196" width="660" height="30" rx="6" fill="#EAE9E7" stroke="#BFBEBA"/>
<text x="370" y="215.5" class="c sub b">宿主机的 Linux 内核</text>
<text x="30" y="244" class="sub">各容器的依赖互不影响,同一个镜像在开发机、测试环境和生产环境中运行结果一致。</text>
</svg>

After

Width:  |  Height:  |  Size: 4.0 KiB