id: 9dbe5479fba740c2ac084b2dc431ad4a
parent_id: 
item_type: 1
item_id: a5f75cc2a5bc4f31ab7cf0e99240bceb
item_updated_time: 1764345613541
title_diff: "[{\"diffs\":[[1,\"Docker入门系列——网络\"]],\"start1\":0,\"start2\":0,\"length1\":0,\"length2\":14}]"
body_diff: "[{\"diffs\":[[1,\"<html>\\\r\\\n<head>\\\r\\\n  <title>Docker入门系列——网络</title>\\\r\\\n  <basefont face=\\\"微软雅黑\\\" size=\\\"2\\\" />\\\r\\\n  <meta http-equiv=\\\"Content-Type\\\" content=\\\"text/html;charset=utf-8\\\" />\\\r\\\n  <meta name=\\\"exporter-version\\\" content=\\\"YXBJ Windows/608924 (zh-CN, DDL); Windows/10.0.0 (Win64); EDAMVersion=V2;\\\"/>\\\r\\\n  <meta name=\\\"content-class\\\" content=\\\"yinxiang.peso.superNote\\\"/>\\\r\\\n  <meta name=\\\"application-data:yinxiang.noteLayout\\\" content=\\\"{\\\"lineSpace\\\":\\\"recommend\\\",\\\"paragraphSpace\\\":\\\"recommend\\\"}\\\"/>\\\r\\\n  <style>\\\r\\\n\\tbody, td {\\\r\\\n\\t  font-family: 微软雅黑;\\\r\\\n\\t  font-size: 12pt;\\\r\\\n\\t}\\\r\\\n  </style>\\\r\\\n</head>\\\r\\\n<body>\\\r\\\n<a name=\\\"35102\\\"></a>\\\r\\\n<h1>Docker入门系列——网络</h1>\\\r\\\n\\\r\\\n<div><span style=\\\"margin:0px;\\\"><div style=\\\"padding:8px 0px;margin:8px auto;max-width:700px;\\\"> <div><span></span></div>\\\n<p></p>\\\n<div style=\\\"--en-blockquote:true;box-sizing: border-box; padding-left: 19px; padding-top: 6px; padding-bottom: 6px; border-left: 3px solid #b4c0cc; background-position: initial initial; background-repeat: initial initial; margin-top: 6px\\\"><div>原文链接: <a href=\\\"http://mp.weixin.qq.com/s?__biz=Mzk0NjY0MTc0NA==&amp;mid=2247485377&amp;idx=1&amp;sn=4879065fc6e272fdf538018869989b75&amp;chksm=c2c706d36803c3b09f6606ed59e2de5de06660cedf8aeefae8b482d7eec1884ff2a3566d3cb7&amp;mpshare=1&amp;scene=1&amp;srcid=1225Kn658w99GUzvG8T8oXBK&amp;sharer_shareinfo=f8e30fdb93257ed06932ac35df7cdea1&amp;sharer_shareinfo_first=f8e30fdb93257ed06932ac35df7cdea1#rd\\\"><span>http://mp.weixin.qq.com/s?__biz=Mzk0NjY0MTc0NA==&amp;mid=2247485...</span></a></div></div>\\\n<p></p>\\\n<div><span></span></div>\\\n<div style=\\\"-webkit-tap-highlight-color:transparent;\\\"><div style=\\\"-webkit-tap-highlight-color:transparent;\\\"><div style=\\\"-webkit-tap-highlight-color:transparent;\\\"><h1 style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"> Docker入门系列——网络 </h1><div style=\\\"-webkit-tap-highlight-color:transparent;\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;position:relative\\\">原创</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> 一叶扁舟 </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><a style=\\\"-webkit-tap-highlight-color:transparent;position:relative\\\"> 代码麻辣烫 </a></span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><em style=\\\"-webkit-tap-highlight-color:transparent\\\"></em></span></div><div style=\\\"-webkit-tap-highlight-color:transparent;\\\"><div style=\\\"-webkit-tap-highlight-color:transparent;margin-bottom:0;padding-left:10px;padding-right:10px;background-attachment:scroll;background-clip:border-box;background-image:linear-gradient(90deg,rgba(50,0,0,0.03) 0,rgba(255,255,255,0) 11.49%),linear-gradient(360deg,rgba(50,0,0,0.04) 0,rgba(255,255,255,0) 12.16%);background-origin:padding-box;background-position:0 0;background-repeat:repeat,repeat;background-size:20px 20px,20px 20px;width:auto;font-family:Optima,PingFangSC-light,serif;font-size:16px;color:rgb(0,0,0);line-height:1.5em;word-spacing:0;letter-spacing:0;word-break:break-word;text-align:left;\\\"><div style=\\\"-webkit-tap-highlight-color:transparent;margin-top:10px;margin-bottom:10px;display:flex;flex-direction:column;justify-content:center;align-items:center;\\\"><img src=\\\":/a2e2f6585f5d479fb50f91ad2e894708\\\" type=\\\"image/png\\\" data-filename=\\\"640.png\\\" style=\\\"--en-marks:%7B%22align%22%3A%22center%22%7D;-webkit-tap-highlight-color:transparent;display:block;margin-right:auto;margin-left:auto;border-style:none;border-width:3px;border-color:rgba(0,0,0,0.4);border-radius:8px;object-fit:fill;box-shadow:rgb(153,153,153) 2px 4px 8px 0;height:auto !important\\\"/></div><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;color:rgb(43,43,43);font-size:14px;line-height:1.8em;letter-spacing:0.02em;text-indent:0;padding-top:8px;padding-bottom:8px\\\">Docker 通过容器化应用程序，彻底改变了我们构建、分发和运行应用程序的方式。然而，有效使用 Docker 的一个关键方面是理解容器如何相互通信以及与外界通信。</p><h2 style=\\\"-webkit-tap-highlight-color:transparent;margin:0;border-color:rgb(0,0,0) rgb(0,0,0) rgb(64,184,250);margin-top:30px;margin-bottom:15px;align-items:unset;background-attachment:scroll;background-clip:border-box;background-image:none;background-origin:padding-box;background-position:0 0;background-repeat:no-repeat;background-size:auto;border-style:none none solid;border-width:1px 1px 4px;border-radius:0;box-shadow:none;flex-direction:unset;float:unset;height:auto;justify-content:unset;line-height:1.5em;overflow:unset;text-shadow:none;transform:none;width:auto;-webkit-box-reflect:unset\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;background-attachment:scroll;background-clip:border-box;background-image:url(https://mmbiz.qpic.cn/sz_mmbiz_png/bA6ibvWzutIZQE6MAqh3pAcTaICuVEgA6ERpC8WHMy8YFs9MMyYiapbY5qstAkqw21ib3KmPwJF9UqHjnibMfa6e1g/640?wx_fmt=png&amp;from=appmsg);background-origin:padding-box;background-position:0 0;background-repeat:no-repeat;background-size:20px 20px;width:20px;height:20px;align-items:unset;border-style:none;border-width:1px;border-color:rgb(0,0,0);border-radius:0;box-shadow:none;display:flex;font-size:22px;font-weight:bold;flex-direction:unset;float:unset;justify-content:unset;letter-spacing:0;line-height:1.5em;margin-bottom:-25px;overflow:unset;text-indent:0;text-shadow:none;transform:none;-webkit-box-reflect:unset\\\"></span><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:20px;color:rgb(64,184,250);line-height:1.5em;letter-spacing:0;align-items:unset;background-attachment:scroll;background-clip:border-box;background-image:none;background-origin:padding-box;background-position:0 0;background-repeat:no-repeat;background-size:auto;border-style:none;border-width:1px;border-color:rgb(0,0,0);border-radius:0;box-shadow:none;display:flex;font-weight:bold;flex-direction:unset;float:unset;height:auto;justify-content:unset;margin-left:25px;overflow:unset;text-indent:0;text-shadow:none;transform:none;width:auto;-webkit-box-reflect:unset\\\">1. 什么是 Docker 网络？</span><span style=\\\"-webkit-tap-highlight-color:transparent;background:none 0 0/auto no-repeat scroll padding-box border-box rgba(64,184,250,0.5);align-items:unset;border-style:none;border-width:1px;border-color:rgb(0,0,0);border-radius:20px 0 0;box-shadow:none;display:flex;font-size:22px;font-weight:bold;flex-direction:unset;float:right;height:10px;justify-content:unset;letter-spacing:0;line-height:1.5em;margin-top:-10px;overflow:unset;text-indent:0;text-shadow:none;transform:none;width:200px;-webkit-box-reflect:unset\\\"></span></h2><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;color:rgb(43,43,43);font-size:14px;line-height:1.8em;letter-spacing:0.02em;text-indent:0;padding-top:8px;padding-bottom:8px\\\">Docker 网络允许容器相互通信以及与外部资源通信。默认情况下，每个容器都是隔离的，这意味着除非连接到共享网络，否则它们不会自动与其他容器通信。Docker 提供了一个灵活且强大的网络模型，简化了容器之间的连接。</p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;color:rgb(43,43,43);font-size:14px;line-height:1.8em;letter-spacing:0.02em;text-indent:0;padding-top:8px;padding-bottom:8px\\\">简而言之，Docker 网络处理：</p><ul style=\\\"-webkit-tap-highlight-color:transparent;margin:0;margin-top:8px;margin-bottom:8px;padding-left:25px\\\"><li style=\\\"-webkit-tap-highlight-color:transparent\\\"><div style=\\\"-webkit-tap-highlight-color:transparent;margin-top:5px;margin-bottom:5px;color:rgb(89,89,89);font-size:14px;line-height:1.8em;letter-spacing:0.02em;\\\">容器之间的通信</div></li><li style=\\\"-webkit-tap-highlight-color:transparent\\\"><div style=\\\"-webkit-tap-highlight-color:transparent;margin-top:5px;margin-bottom:5px;color:rgb(89,89,89);font-size:14px;line-height:1.8em;letter-spacing:0.02em;\\\">容器与外界的通信</div></li><li style=\\\"-webkit-tap-highlight-color:transparent\\\"><div style=\\\"-webkit-tap-highlight-color:transparent;margin-top:5px;margin-bottom:5px;color:rgb(89,89,89);font-size:14px;line-height:1.8em;letter-spacing:0.02em;\\\">为容器化应用程序定义隔离边界</div></li></ul><h2 style=\\\"-webkit-tap-highlight-color:transparent;margin:0;border-color:rgb(0,0,0) rgb(0,0,0) rgb(64,184,250);margin-top:30px;margin-bottom:15px;align-items:unset;background-attachment:scroll;background-clip:border-box;background-image:none;background-origin:padding-box;background-position:0 0;background-repeat:no-repeat;background-size:auto;border-style:none none solid;border-width:1px 1px 4px;border-radius:0;box-shadow:none;flex-direction:unset;float:unset;height:auto;justify-content:unset;line-height:1.5em;overflow:unset;text-shadow:none;transform:none;width:auto;-webkit-box-reflect:unset\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;background-attachment:scroll;background-clip:border-box;background-image:url(https://mmbiz.qpic.cn/sz_mmbiz_png/bA6ibvWzutIZQE6MAqh3pAcTaICuVEgA6ERpC8WHMy8YFs9MMyYiapbY5qstAkqw21ib3KmPwJF9UqHjnibMfa6e1g/640?wx_fmt=png&amp;from=appmsg);background-origin:padding-box;background-position:0 0;background-repeat:no-repeat;background-size:20px 20px;width:20px;height:20px;align-items:unset;border-style:none;border-width:1px;border-color:rgb(0,0,0);border-radius:0;box-shadow:none;display:flex;font-size:22px;font-weight:bold;flex-direction:unset;float:unset;justify-content:unset;letter-spacing:0;line-height:1.5em;margin-bottom:-25px;overflow:unset;text-indent:0;text-shadow:none;transform:none;-webkit-box-reflect:unset\\\"></span><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:20px;color:rgb(64,184,250);line-height:1.5em;letter-spacing:0;align-items:unset;background-attachment:scroll;background-clip:border-box;background-image:none;background-origin:padding-box;background-position:0 0;background-repeat:no-repeat;background-size:auto;border-style:none;border-width:1px;border-color:rgb(0,0,0);border-radius:0;box-shadow:none;display:flex;font-weight:bold;flex-direction:unset;float:unset;height:auto;justify-content:unset;margin-left:25px;overflow:unset;text-indent:0;text-shadow:none;transform:none;width:auto;-webkit-box-reflect:unset\\\">2. Docker 网络类型</span><span style=\\\"-webkit-tap-highlight-color:transparent;background:none 0 0/auto no-repeat scroll padding-box border-box rgba(64,184,250,0.5);align-items:unset;border-style:none;border-width:1px;border-color:rgb(0,0,0);border-radius:20px 0 0;box-shadow:none;display:flex;font-size:22px;font-weight:bold;flex-direction:unset;float:right;height:10px;justify-content:unset;letter-spacing:0;line-height:1.5em;margin-top:-10px;overflow:unset;text-indent:0;text-shadow:none;transform:none;width:200px;-webkit-box-reflect:unset\\\"></span></h2><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;color:rgb(43,43,43);font-size:14px;line-height:1.8em;letter-spacing:0.02em;text-indent:0;padding-top:8px;padding-bottom:8px\\\">Docker 提供了几种网络驱动程序，每种都适用于不同的用例。了解这些网络类型对于为您的应用程序选择正确的网络至关重要。</p><h3 style=\\\"-webkit-tap-highlight-color:transparent;margin:0;margin-top:30px;margin-bottom:15px;border-style:none;border-width:1px;border-color:rgb(0,0,0);border-radius:0;background-attachment:scroll;background-clip:border-box;background-image:url(https://mmbiz.qpic.cn/sz_mmbiz_png/bA6ibvWzutIZQE6MAqh3pAcTaICuVEgA6V17nSSNkBhZbiaj4azxSb6MYWYQEUGzw5FFq2iaK2nO6Twa8Y09DWL5A/640?wx_fmt=png&amp;from=appmsg);background-origin:padding-box;background-position:50% 50%;background-repeat:no-repeat;background-size:30px 30px;width:auto;height:auto;align-items:unset;box-shadow:none;display:flex;flex-direction:unset;float:unset;justify-content:center;line-height:1.5em;overflow:unset;text-shadow:none;transform:none;-webkit-box-reflect:unset\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:18px;color:rgb(43,43,43);line-height:2.4em;letter-spacing:0;margin-top:38px;margin-bottom:10px;align-items:unset;background-attachment:scroll;background-clip:border-box;background-image:none;background-origin:padding-box;background-position:0 0;background-repeat:no-repeat;background-size:auto;border-style:none;border-width:1px;border-color:rgb(0,0,0);border-radius:0;box-shadow:none;display:inline-block;font-weight:bold;flex-direction:unset;float:unset;height:38px;justify-content:unset;overflow:unset;text-align:center;text-indent:0;text-shadow:none;transform:none;width:auto;-webkit-box-reflect:unset\\\">桥接网络（默认）</span></h3><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;color:rgb(43,43,43);font-size:14px;line-height:1.8em;letter-spacing:0.02em;text-indent:0;padding-top:8px;padding-bottom:8px\\\">桥接网络是 Docker 在创建容器时使用的默认网络驱动程序。同一桥接网络上的容器可以使用 IP 地址或容器名称相互通信。</p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;color:rgb(43,43,43);font-size:14px;line-height:1.8em;letter-spacing:0.02em;text-indent:0;padding-top:8px;padding-bottom:8px\\\"><strong style=\\\"-webkit-tap-highlight-color:transparent;color:rgb(53,148,247);background-attachment:scroll;background-clip:border-box;background-image:none;background-origin:padding-box;background-position:0 0;background-repeat:no-repeat;background-size:auto;width:auto;height:auto;border-style:none;border-width:3px;border-color:rgba(0,0,0,0.4);border-radius:0\\\">用例：</strong> 这通常用于需要在单个主机上内部通信的多容器应用程序，例如开发环境中的微服务。</p><pre style=\\\"-webkit-tap-highlight-color:transparent;border-radius:5px;box-shadow:rgba(0,0,0,0.55) 0 2px 10px;margin-top:10px;margin-bottom:10px\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;display:block;background:url(https://mmbiz.qpic.cn/mmbiz_svg/eHEMOF2hOelPPWBYXFCk1jia9ZXzQo1KF8wX9pTiaFJDNgF8sEkJ1sWhSvfC4Eb5MnOsGjeMq8l3d4BeypK0PVYBgicGYQBo6gM/640?wx_fmt=svg&amp;from=appmsg) 10px 10px/40px no-repeat rgb(40,44,52);height:30px;width:100%;margin-bottom:-7px;border-radius:5px\\\"></span><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;color:#5c6370;font-style:italic;line-height:26px\\\"># 列出默认桥接网络上的容器</span><br style=\\\"-webkit-tap-highlight-color:transparent\\\"/>docker network inspect bridge<br style=\\\"-webkit-tap-highlight-color:transparent\\\"/></div></pre><h3 style=\\\"-webkit-tap-highlight-color:transparent;margin:0;margin-top:30px;margin-bottom:15px;border-style:none;border-width:1px;border-color:rgb(0,0,0);border-radius:0;background-attachment:scroll;background-clip:border-box;background-image:url(https://mmbiz.qpic.cn/sz_mmbiz_png/bA6ibvWzutIZQE6MAqh3pAcTaICuVEgA6V17nSSNkBhZbiaj4azxSb6MYWYQEUGzw5FFq2iaK2nO6Twa8Y09DWL5A/640?wx_fmt=png&amp;from=appmsg);background-origin:padding-box;background-position:50% 50%;background-repeat:no-repeat;background-size:30px 30px;width:auto;height:auto;align-items:unset;box-shadow:none;display:flex;flex-direction:unset;float:unset;justify-content:center;line-height:1.5em;overflow:unset;text-shadow:none;transform:none;-webkit-box-reflect:unset\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:18px;color:rgb(43,43,43);line-height:2.4em;letter-spacing:0;margin-top:38px;margin-bottom:10px;align-items:unset;background-attachment:scroll;background-clip:border-box;background-image:none;background-origin:padding-box;background-position:0 0;background-repeat:no-repeat;background-size:auto;border-style:none;border-width:1px;border-color:rgb(0,0,0);border-radius:0;box-shadow:none;display:inline-block;font-weight:bold;flex-direction:unset;float:unset;height:38px;justify-content:unset;overflow:unset;text-align:center;text-indent:0;text-shadow:none;transform:none;width:auto;-webkit-box-reflect:unset\\\">主机网络</span></h3><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;color:rgb(43,43,43);font-size:14px;line-height:1.8em;letter-spacing:0.02em;text-indent:0;padding-top:8px;padding-bottom:8px\\\">在主机网络中，容器共享主机的网络命名空间。这意味着容器可以直接使用主机的 IP 地址和端口。</p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;color:rgb(43,43,43);font-size:14px;line-height:1.8em;letter-spacing:0.02em;text-indent:0;padding-top:8px;padding-bottom:8px\\\"><strong style=\\\"-webkit-tap-highlight-color:transparent;color:rgb(53,148,247);background-attachment:scroll;background-clip:border-box;background-image:none;background-origin:padding-box;background-position:0 0;background-repeat:no-repeat;background-size:auto;width:auto;height:auto;border-style:none;border-width:3px;border-color:rgba(0,0,0,0.4);border-radius:0\\\">用例：</strong> 这适用于需要避免网络开销的性能关键型应用程序，但您会失去容器与主机之间的隔离。</p><pre style=\\\"-webkit-tap-highlight-color:transparent;border-radius:5px;box-shadow:rgba(0,0,0,0.55) 0 2px 10px;margin-top:10px;margin-bottom:10px\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;display:block;background:url(https://mmbiz.qpic.cn/mmbiz_svg/eHEMOF2hOelPPWBYXFCk1jia9ZXzQo1KF8wX9pTiaFJDNgF8sEkJ1sWhSvfC4Eb5MnOsGjeMq8l3d4BeypK0PVYBgicGYQBo6gM/640?wx_fmt=svg&amp;from=appmsg) 10px 10px/40px no-repeat rgb(40,44,52);height:30px;width:100%;margin-bottom:-7px;border-radius:5px\\\"></span><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\">docker run --network host &lt;image&gt;<br style=\\\"-webkit-tap-highlight-color:transparent\\\"/></div></pre><h3 style=\\\"-webkit-tap-highlight-color:transparent;margin:0;margin-top:30px;margin-bottom:15px;border-style:none;border-width:1px;border-color:rgb(0,0,0);border-radius:0;background-attachment:scroll;background-clip:border-box;background-image:url(https://mmbiz.qpic.cn/sz_mmbiz_png/bA6ibvWzutIZQE6MAqh3pAcTaICuVEgA6V17nSSNkBhZbiaj4azxSb6MYWYQEUGzw5FFq2iaK2nO6Twa8Y09DWL5A/640?wx_fmt=png&amp;from=appmsg);background-origin:padding-box;background-position:50% 50%;background-repeat:no-repeat;background-size:30px 30px;width:auto;height:auto;align-items:unset;box-shadow:none;display:flex;flex-direction:unset;float:unset;justify-content:center;line-height:1.5em;overflow:unset;text-shadow:none;transform:none;-webkit-box-reflect:unset\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:18px;color:rgb(43,43,43);line-height:2.4em;letter-spacing:0;margin-top:38px;margin-bottom:10px;align-items:unset;background-attachment:scroll;background-clip:border-box;background-image:none;background-origin:padding-box;background-position:0 0;background-repeat:no-repeat;background-size:auto;border-style:none;border-width:1px;border-color:rgb(0,0,0);border-radius:0;box-shadow:none;display:inline-block;font-weight:bold;flex-direction:unset;float:unset;height:38px;justify-content:unset;overflow:unset;text-align:center;text-indent:0;text-shadow:none;transform:none;width:auto;-webkit-box-reflect:unset\\\">无网络</span></h3><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;color:rgb(43,43,43);font-size:14px;line-height:1.8em;letter-spacing:0.02em;text-indent:0;padding-top:8px;padding-bottom:8px\\\">顾名思义，<code style=\\\"-webkit-tap-highlight-color:transparent;color:rgb(53,148,247);line-height:1.8em;letter-spacing:0;background:none 0 0/auto no-repeat scroll padding-box border-box rgba(27,31,35,0.05);width:auto;height:auto;margin-left:2px;margin-right:2px;padding:2px 4px;border-style:none;border-width:3px;border-color:rgb(0,0,0) rgba(0,0,0,0.4) rgba(0,0,0,0.4);border-radius:4px;font-family:&quot;Operator Mono&quot;,Consolas,Monaco,Menlo,monospace;word-break:break-all\\\">none</code> 网络驱动程序禁用了容器的所有网络功能。当容器不需要任何外部或内部网络时，这很有用。</p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;color:rgb(43,43,43);font-size:14px;line-height:1.8em;letter-spacing:0.02em;text-indent:0;padding-top:8px;padding-bottom:8px\\\"><strong style=\\\"-webkit-tap-highlight-color:transparent;color:rgb(53,148,247);background-attachment:scroll;background-clip:border-box;background-image:none;background-origin:padding-box;background-position:0 0;background-repeat:no-repeat;background-size:auto;width:auto;height:auto;border-style:none;border-width:3px;border-color:rgba(0,0,0,0.4);border-radius:0\\\">用例：</strong> 用于不需要任何网络通信的容器，例如特定的后台任务。</p><pre style=\\\"-webkit-tap-highlight-color:transparent;border-radius:5px;box-shadow:rgba(0,0,0,0.55) 0 2px 10px;margin-top:10px;margin-bottom:10px\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;display:block;background:url(https://mmbiz.qpic.cn/mmbiz_svg/eHEMOF2hOelPPWBYXFCk1jia9ZXzQo1KF8wX9pTiaFJDNgF8sEkJ1sWhSvfC4Eb5MnOsGjeMq8l3d4BeypK0PVYBgicGYQBo6gM/640?wx_fmt=svg&amp;from=appmsg) 10px 10px/40px no-repeat rgb(40,44,52);height:30px;width:100%;margin-bottom:-7px;border-radius:5px\\\"></span><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\">docker run --network none &lt;image&gt;<br style=\\\"-webkit-tap-highlight-color:transparent\\\"/></div></pre><h3 style=\\\"-webkit-tap-highlight-color:transparent;margin:0;margin-top:30px;margin-bottom:15px;border-style:none;border-width:1px;border-color:rgb(0,0,0);border-radius:0;background-attachment:scroll;background-clip:border-box;background-image:url(https://mmbiz.qpic.cn/sz_mmbiz_png/bA6ibvWzutIZQE6MAqh3pAcTaICuVEgA6V17nSSNkBhZbiaj4azxSb6MYWYQEUGzw5FFq2iaK2nO6Twa8Y09DWL5A/640?wx_fmt=png&amp;from=appmsg);background-origin:padding-box;background-position:50% 50%;background-repeat:no-repeat;background-size:30px 30px;width:auto;height:auto;align-items:unset;box-shadow:none;display:flex;flex-direction:unset;float:unset;justify-content:center;line-height:1.5em;overflow:unset;text-shadow:none;transform:none;-webkit-box-reflect:unset\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:18px;color:rgb(43,43,43);line-height:2.4em;letter-spacing:0;margin-top:38px;margin-bottom:10px;align-items:unset;background-attachment:scroll;background-clip:border-box;background-image:none;background-origin:padding-box;background-position:0 0;background-repeat:no-repeat;background-size:auto;border-style:none;border-width:1px;border-color:rgb(0,0,0);border-radius:0;box-shadow:none;display:inline-block;font-weight:bold;flex-direction:unset;float:unset;height:38px;justify-content:unset;overflow:unset;text-align:center;text-indent:0;text-shadow:none;transform:none;width:auto;-webkit-box-reflect:unset\\\">覆盖网络</span></h3><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;color:rgb(43,43,43);font-size:14px;line-height:1.8em;letter-spacing:0.02em;text-indent:0;padding-top:8px;padding-bottom:8px\\\">覆盖网络用于多主机 Docker 设置，其中不同主机上运行的容器需要相互通信。它需要 Docker Swarm 或 Kubernetes 设置。</p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;color:rgb(43,43,43);font-size:14px;line-height:1.8em;letter-spacing:0.02em;text-indent:0;padding-top:8px;padding-bottom:8px\\\"><strong style=\\\"-webkit-tap-highlight-color:transparent;color:rgb(53,148,247);background-attachment:scroll;background-clip:border-box;background-image:none;background-origin:padding-box;background-position:0 0;background-repeat:no-repeat;background-size:auto;width:auto;height:auto;border-style:none;border-width:3px;border-color:rgba(0,0,0,0.4);border-radius:0\\\">用例：</strong> 对于跨多个 Docker 主机的分布式系统至关重要。</p><pre style=\\\"-webkit-tap-highlight-color:transparent;border-radius:5px;box-shadow:rgba(0,0,0,0.55) 0 2px 10px;margin-top:10px;margin-bottom:10px\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;display:block;background:url(https://mmbiz.qpic.cn/mmbiz_svg/eHEMOF2hOelPPWBYXFCk1jia9ZXzQo1KF8wX9pTiaFJDNgF8sEkJ1sWhSvfC4Eb5MnOsGjeMq8l3d4BeypK0PVYBgicGYQBo6gM/640?wx_fmt=svg&amp;from=appmsg) 10px 10px/40px no-repeat rgb(40,44,52);height:30px;width:100%;margin-bottom:-7px;border-radius:5px\\\"></span><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\">docker network create --driver overlay my-overlay-network<br style=\\\"-webkit-tap-highlight-color:transparent\\\"/></div></pre><hr style=\\\"-webkit-tap-highlight-color:transparent;margin-top:10px;margin-bottom:10px;border-style:solid none none;border-width:2px 3px 3px;border-color:rgb(59,170,250) rgba(0,0,0,0.4) rgba(0,0,0,0.4);border-radius:0;background-attachment:scroll;background-clip:border-box;background-image:none;background-origin:padding-box;background-position:0 0;background-repeat:no-repeat;background-size:auto;width:auto;height:1px\\\"/><h2 style=\\\"-webkit-tap-highlight-color:transparent;margin:0;border-color:rgb(0,0,0) rgb(0,0,0) rgb(64,184,250);margin-top:30px;margin-bottom:15px;align-items:unset;background-attachment:scroll;background-clip:border-box;background-image:none;background-origin:padding-box;background-position:0 0;background-repeat:no-repeat;background-size:auto;border-style:none none solid;border-width:1px 1px 4px;border-radius:0;box-shadow:none;flex-direction:unset;float:unset;height:auto;justify-content:unset;line-height:1.5em;overflow:unset;text-shadow:none;transform:none;width:auto;-webkit-box-reflect:unset\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;background-attachment:scroll;background-clip:border-box;background-image:url(https://mmbiz.qpic.cn/sz_mmbiz_png/bA6ibvWzutIZQE6MAqh3pAcTaICuVEgA6ERpC8WHMy8YFs9MMyYiapbY5qstAkqw21ib3KmPwJF9UqHjnibMfa6e1g/640?wx_fmt=png&amp;from=appmsg);background-origin:padding-box;background-position:0 0;background-repeat:no-repeat;background-size:20px 20px;width:20px;height:20px;align-items:unset;border-style:none;border-width:1px;border-color:rgb(0,0,0);border-radius:0;box-shadow:none;display:flex;font-size:22px;font-weight:bold;flex-direction:unset;float:unset;justify-content:unset;letter-spacing:0;line-height:1.5em;margin-bottom:-25px;overflow:unset;text-indent:0;text-shadow:none;transform:none;-webkit-box-reflect:unset\\\"></span><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:20px;color:rgb(64,184,250);line-height:1.5em;letter-spacing:0;align-items:unset;background-attachment:scroll;background-clip:border-box;background-image:none;background-origin:padding-box;background-position:0 0;background-repeat:no-repeat;background-size:auto;border-style:none;border-width:1px;border-color:rgb(0,0,0);border-radius:0;box-shadow:none;display:flex;font-weight:bold;flex-direction:unset;float:unset;height:auto;justify-content:unset;margin-left:25px;overflow:unset;text-indent:0;text-shadow:none;transform:none;width:auto;-webkit-box-reflect:unset\\\">3. Docker 网络实战</span><span style=\\\"-webkit-tap-highlight-color:transparent;background:none 0 0/auto no-repeat scroll padding-box border-box rgba(64,184,250,0.5);align-items:unset;border-style:none;border-width:1px;border-color:rgb(0,0,0);border-radius:20px 0 0;box-shadow:none;display:flex;font-size:22px;font-weight:bold;flex-direction:unset;float:right;height:10px;justify-content:unset;letter-spacing:0;line-height:1.5em;margin-top:-10px;overflow:unset;text-indent:0;text-shadow:none;transform:none;width:200px;-webkit-box-reflect:unset\\\"></span></h2><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;color:rgb(43,43,43);font-size:14px;line-height:1.8em;letter-spacing:0.02em;text-indent:0;padding-top:8px;padding-bottom:8px\\\">现在，让我们探索如何在现实世界场景中使用 Docker 网络。</p><h3 style=\\\"-webkit-tap-highlight-color:transparent;margin:0;margin-top:30px;margin-bottom:15px;border-style:none;border-width:1px;border-color:rgb(0,0,0);border-radius:0;background-attachment:scroll;background-clip:border-box;background-image:url(https://mmbiz.qpic.cn/sz_mmbiz_png/bA6ibvWzutIZQE6MAqh3pAcTaICuVEgA6V17nSSNkBhZbiaj4azxSb6MYWYQEUGzw5FFq2iaK2nO6Twa8Y09DWL5A/640?wx_fmt=png&amp;from=appmsg);background-origin:padding-box;background-position:50% 50%;background-repeat:no-repeat;background-size:30px 30px;width:auto;height:auto;align-items:unset;box-shadow:none;display:flex;flex-direction:unset;float:unset;justify-content:center;line-height:1.5em;overflow:unset;text-shadow:none;transform:none;-webkit-box-reflect:unset\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:18px;color:rgb(43,43,43);line-height:2.4em;letter-spacing:0;margin-top:38px;margin-bottom:10px;align-items:unset;background-attachment:scroll;background-clip:border-box;background-image:none;background-origin:padding-box;background-position:0 0;background-repeat:no-repeat;background-size:auto;border-style:none;border-width:1px;border-color:rgb(0,0,0);border-radius:0;box-shadow:none;display:inline-block;font-weight:bold;flex-direction:unset;float:unset;height:38px;justify-content:unset;overflow:unset;text-align:center;text-indent:0;text-shadow:none;transform:none;width:auto;-webkit-box-reflect:unset\\\">创建和管理网络</span></h3><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;color:rgb(43,43,43);font-size:14px;line-height:1.8em;letter-spacing:0.02em;text-indent:0;padding-top:8px;padding-bottom:8px\\\">默认情况下，Docker 在运行容器时会创建一个桥接网络。但是，您可以为更高级的设置创建自定义网络。</p><pre style=\\\"-webkit-tap-highlight-color:transparent;border-radius:5px;box-shadow:rgba(0,0,0,0.55) 0 2px 10px;margin-top:10px;margin-bottom:10px\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;display:block;background:url(https://mmbiz.qpic.cn/mmbiz_svg/eHEMOF2hOelPPWBYXFCk1jia9ZXzQo1KF8wX9pTiaFJDNgF8sEkJ1sWhSvfC4Eb5MnOsGjeMq8l3d4BeypK0PVYBgicGYQBo6gM/640?wx_fmt=svg&amp;from=appmsg) 10px 10px/40px no-repeat rgb(40,44,52);height:30px;width:100%;margin-bottom:-7px;border-radius:5px\\\"></span><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;color:#5c6370;font-style:italic;line-height:26px\\\"># 创建自定义桥接网络</span><br style=\\\"-webkit-tap-highlight-color:transparent\\\"/>docker network create my-custom-network<br style=\\\"-webkit-tap-highlight-color:transparent\\\"/></div></pre><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;color:rgb(43,43,43);font-size:14px;line-height:1.8em;letter-spacing:0.02em;text-indent:0;padding-top:8px;padding-bottom:8px\\\">您可以使用以下命令检查您的网络：</p><pre style=\\\"-webkit-tap-highlight-color:transparent;border-radius:5px;box-shadow:rgba(0,0,0,0.55) 0 2px 10px;margin-top:10px;margin-bottom:10px\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;display:block;background:url(https://mmbiz.qpic.cn/mmbiz_svg/eHEMOF2hOelPPWBYXFCk1jia9ZXzQo1KF8wX9pTiaFJDNgF8sEkJ1sWhSvfC4Eb5MnOsGjeMq8l3d4BeypK0PVYBgicGYQBo6gM/640?wx_fmt=svg&amp;from=appmsg) 10px 10px/40px no-repeat rgb(40,44,52);height:30px;width:100%;margin-bottom:-7px;border-radius:5px\\\"></span><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\">docker network ls  <span style=\\\"-webkit-tap-highlight-color:transparent;color:#5c6370;font-style:italic;line-height:26px\\\"># 列出所有网络</span><br style=\\\"-webkit-tap-highlight-color:transparent\\\"/>docker network inspect my-custom-network  <span style=\\\"-webkit-tap-highlight-color:transparent;color:#5c6370;font-style:italic;line-height:26px\\\"># 关于特定网络的详细信息</span><br style=\\\"-webkit-tap-highlight-color:transparent\\\"/></div></pre><h3 style=\\\"-webkit-tap-highlight-color:transparent;margin:0;margin-top:30px;margin-bottom:15px;border-style:none;border-width:1px;border-color:rgb(0,0,0);border-radius:0;background-attachment:scroll;background-clip:border-box;background-image:url(https://mmbiz.qpic.cn/sz_mmbiz_png/bA6ibvWzutIZQE6MAqh3pAcTaICuVEgA6V17nSSNkBhZbiaj4azxSb6MYWYQEUGzw5FFq2iaK2nO6Twa8Y09DWL5A/640?wx_fmt=png&amp;from=appmsg);background-origin:padding-box;background-position:50% 50%;background-repeat:no-repeat;background-size:30px 30px;width:auto;height:auto;align-items:unset;box-shadow:none;display:flex;flex-direction:unset;float:unset;justify-content:center;line-height:1.5em;overflow:unset;text-shadow:none;transform:none;-webkit-box-reflect:unset\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:18px;color:rgb(43,43,43);line-height:2.4em;letter-spacing:0;margin-top:38px;margin-bottom:10px;align-items:unset;background-attachment:scroll;background-clip:border-box;background-image:none;background-origin:padding-box;background-position:0 0;background-repeat:no-repeat;background-size:auto;border-style:none;border-width:1px;border-color:rgb(0,0,0);border-radius:0;box-shadow:none;display:inline-block;font-weight:bold;flex-direction:unset;float:unset;height:38px;justify-content:unset;overflow:unset;text-align:center;text-indent:0;text-shadow:none;transform:none;width:auto;-webkit-box-reflect:unset\\\">将容器连接到网络</span></h3><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;color:rgb(43,43,43);font-size:14px;line-height:1.8em;letter-spacing:0.02em;text-indent:0;padding-top:8px;padding-bottom:8px\\\">创建自定义网络后，您可以将容器附加到它。</p><pre style=\\\"-webkit-tap-highlight-color:transparent;border-radius:5px;box-shadow:rgba(0,0,0,0.55) 0 2px 10px;margin-top:10px;margin-bottom:10px\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;display:block;background:url(https://mmbiz.qpic.cn/mmbiz_svg/eHEMOF2hOelPPWBYXFCk1jia9ZXzQo1KF8wX9pTiaFJDNgF8sEkJ1sWhSvfC4Eb5MnOsGjeMq8l3d4BeypK0PVYBgicGYQBo6gM/640?wx_fmt=svg&amp;from=appmsg) 10px 10px/40px no-repeat rgb(40,44,52);height:30px;width:100%;margin-bottom:-7px;border-radius:5px\\\"></span><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;color:#5c6370;font-style:italic;line-height:26px\\\"># 运行一个容器并将其附加到自定义网络</span><br style=\\\"-webkit-tap-highlight-color:transparent\\\"/>docker run -d --name container1 --network my-custom-network nginx<br style=\\\"-webkit-tap-highlight-color:transparent\\\"/><br style=\\\"-webkit-tap-highlight-color:transparent\\\"/><span style=\\\"-webkit-tap-highlight-color:transparent;color:#5c6370;font-style:italic;line-height:26px\\\"># 运行另一个容器并将其附加到同一网络</span><br style=\\\"-webkit-tap-highlight-color:transparent\\\"/>docker run -d --name container2 --network my-custom-network redis<br style=\\\"-webkit-tap-highlight-color:transparent\\\"/></div></pre><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;color:rgb(43,43,43);font-size:14px;line-height:1.8em;letter-spacing:0.02em;text-indent:0;padding-top:8px;padding-bottom:8px\\\">同一网络上的容器可以通过容器名称相互通信。</p><pre style=\\\"-webkit-tap-highlight-color:transparent;border-radius:5px;box-shadow:rgba(0,0,0,0.55) 0 2px 10px;margin-top:10px;margin-bottom:10px\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;display:block;background:url(https://mmbiz.qpic.cn/mmbiz_svg/eHEMOF2hOelPPWBYXFCk1jia9ZXzQo1KF8wX9pTiaFJDNgF8sEkJ1sWhSvfC4Eb5MnOsGjeMq8l3d4BeypK0PVYBgicGYQBo6gM/640?wx_fmt=svg&amp;from=appmsg) 10px 10px/40px no-repeat rgb(40,44,52);height:30px;width:100%;margin-bottom:-7px;border-radius:5px\\\"></span><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;color:#5c6370;font-style:italic;line-height:26px\\\"># 在 container1 内部，您可以通过名称访问 container2</span><br style=\\\"-webkit-tap-highlight-color:transparent\\\"/>ping container2<br style=\\\"-webkit-tap-highlight-color:transparent\\\"/></div></pre><h3 style=\\\"-webkit-tap-highlight-color:transparent;margin:0;margin-top:30px;margin-bottom:15px;border-style:none;border-width:1px;border-color:rgb(0,0,0);border-radius:0;background-attachment:scroll;background-clip:border-box;background-image:url(https://mmbiz.qpic.cn/sz_mmbiz_png/bA6ibvWzutIZQE6MAqh3pAcTaICuVEgA6V17nSSNkBhZbiaj4azxSb6MYWYQEUGzw5FFq2iaK2nO6Twa8Y09DWL5A/640?wx_fmt=png&amp;from=appmsg);background-origin:padding-box;background-position:50% 50%;background-repeat:no-repeat;background-size:30px 30px;width:auto;height:auto;align-items:unset;box-shadow:none;display:flex;flex-direction:unset;float:unset;justify-content:center;line-height:1.5em;overflow:unset;text-shadow:none;transform:none;-webkit-box-reflect:unset\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:18px;color:rgb(43,43,43);line-height:2.4em;letter-spacing:0;margin-top:38px;margin-bottom:10px;align-items:unset;background-attachment:scroll;background-clip:border-box;background-image:none;background-origin:padding-box;background-position:0 0;background-repeat:no-repeat;background-size:auto;border-style:none;border-width:1px;border-color:rgb(0,0,0);border-radius:0;box-shadow:none;display:inline-block;font-weight:bold;flex-direction:unset;float:unset;height:38px;justify-content:unset;overflow:unset;text-align:center;text-indent:0;text-shadow:none;transform:none;width:auto;-webkit-box-reflect:unset\\\">将服务暴露给主机</span></h3><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;color:rgb(43,43,43);font-size:14px;line-height:1.8em;letter-spacing:0.02em;text-indent:0;padding-top:8px;padding-bottom:8px\\\">如果您希望容器内运行的服务能够从主机或外部世界访问，您需要暴露其端口。</p><pre style=\\\"-webkit-tap-highlight-color:transparent;border-radius:5px;box-shadow:rgba(0,0,0,0.55) 0 2px 10px;margin-top:10px;margin-bottom:10px\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;display:block;background:url(https://mmbiz.qpic.cn/mmbiz_svg/eHEMOF2hOelPPWBYXFCk1jia9ZXzQo1KF8wX9pTiaFJDNgF8sEkJ1sWhSvfC4Eb5MnOsGjeMq8l3d4BeypK0PVYBgicGYQBo6gM/640?wx_fmt=svg&amp;from=appmsg) 10px 10px/40px no-repeat rgb(40,44,52);height:30px;width:100%;margin-bottom:-7px;border-radius:5px\\\"></span><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\">docker run -d -p 8080:80 --name webserver nginx<br style=\\\"-webkit-tap-highlight-color:transparent\\\"/></div></pre><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;color:rgb(43,43,43);font-size:14px;line-height:1.8em;letter-spacing:0.02em;text-indent:0;padding-top:8px;padding-bottom:8px\\\">在这种情况下，容器内运行的 Nginx Web 服务器将可以通过主机机器上的 <code style=\\\"-webkit-tap-highlight-color:transparent;color:rgb(53,148,247);line-height:1.8em;letter-spacing:0;background:none 0 0/auto no-repeat scroll padding-box border-box rgba(27,31,35,0.05);width:auto;height:auto;margin-left:2px;margin-right:2px;padding:2px 4px;border-style:none;border-width:3px;border-color:rgb(0,0,0) rgba(0,0,0,0.4) rgba(0,0,0,0.4);border-radius:4px;font-family:&quot;Operator Mono&quot;,Consolas,Monaco,Menlo,monospace;word-break:break-all\\\">localhost:8080</code> 访问。</p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;color:rgb(43,43,43);font-size:14px;line-height:1.8em;letter-spacing:0.02em;text-indent:0;padding-top:8px;padding-bottom:8px\\\">为确保容器间通信高效且安全，优化 Docker 网络配置是关键。以下是一些推荐的优化策略：</p><h3 style=\\\"-webkit-tap-highlight-color:transparent;margin:0;margin-top:30px;margin-bottom:15px;border-style:none;border-width:1px;border-color:rgb(0,0,0);border-radius:0;background-attachment:scroll;background-clip:border-box;background-image:url(https://mmbiz.qpic.cn/sz_mmbiz_png/bA6ibvWzutIZQE6MAqh3pAcTaICuVEgA6V17nSSNkBhZbiaj4azxSb6MYWYQEUGzw5FFq2iaK2nO6Twa8Y09DWL5A/640?wx_fmt=png&amp;from=appmsg);background-origin:padding-box;background-position:50% 50%;background-repeat:no-repeat;background-size:30px 30px;width:auto;height:auto;align-items:unset;box-shadow:none;display:flex;flex-direction:unset;float:unset;justify-content:center;line-height:1.5em;overflow:unset;text-shadow:none;transform:none;-webkit-box-reflect:unset\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:18px;color:rgb(43,43,43);line-height:2.4em;letter-spacing:0;margin-top:38px;margin-bottom:10px;align-items:unset;background-attachment:scroll;background-clip:border-box;background-image:none;background-origin:padding-box;background-position:0 0;background-repeat:no-repeat;background-size:auto;border-style:none;border-width:1px;border-color:rgb(0,0,0);border-radius:0;box-shadow:none;display:inline-block;font-weight:bold;flex-direction:unset;float:unset;height:38px;justify-content:unset;overflow:unset;text-align:center;text-indent:0;text-shadow:none;transform:none;width:auto;-webkit-box-reflect:unset\\\">选择合适的网络模式</span></h3><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;color:rgb(43,43,43);font-size:14px;line-height:1.8em;letter-spacing:0.02em;text-indent:0;padding-top:8px;padding-bottom:8px\\\">Docker 提供的不同网络模式适用于不同的场景，合理选择可以提高应用程序的性能和安全性。</p><ul style=\\\"-webkit-tap-highlight-color:transparent;margin:0;margin-top:8px;margin-bottom:8px;padding-left:25px\\\"><li style=\\\"-webkit-tap-highlight-color:transparent\\\"><div style=\\\"-webkit-tap-highlight-color:transparent;margin-top:5px;margin-bottom:5px;color:rgb(89,89,89);font-size:14px;line-height:1.8em;letter-spacing:0.02em;\\\">桥接网络：适合单主机、多容器之间的通信，典型的使用场景是开发环境的微服务。使用自定义桥接网络能够灵活命名容器，便于容器名称解析。</div></li><li style=\\\"-webkit-tap-highlight-color:transparent\\\"><div style=\\\"-webkit-tap-highlight-color:transparent;margin-top:5px;margin-bottom:5px;color:rgb(89,89,89);font-size:14px;line-height:1.8em;letter-spacing:0.02em;\\\">主机网络：适合高性能应用，因为它消除了 NAT（网络地址转换）带来的网络开销。但使用主机网络时容器会共享主机的网络命名空间，因此隔离性会降低，适用于信任容器的场景。</div></li><li style=\\\"-webkit-tap-highlight-color:transparent\\\"><div style=\\\"-webkit-tap-highlight-color:transparent;margin-top:5px;margin-bottom:5px;color:rgb(89,89,89);font-size:14px;line-height:1.8em;letter-spacing:0.02em;\\\">覆盖网络：用于多主机 Docker Swarm 或 Kubernetes 集群中，可以跨多主机的容器间通信。分布式系统或集群应用建议选择覆盖网络。</div></li><li style=\\\"-webkit-tap-highlight-color:transparent\\\"><div style=\\\"-webkit-tap-highlight-color:transparent;margin-top:5px;margin-bottom:5px;color:rgb(89,89,89);font-size:14px;line-height:1.8em;letter-spacing:0.02em;\\\">无网络模式：适合无需网络的容器，例如单纯的数据处理或备份任务等。</div></li></ul><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;color:rgb(43,43,43);font-size:14px;line-height:1.8em;letter-spacing:0.02em;text-indent:0;padding-top:8px;padding-bottom:8px\\\">使用 docker network ls 可以列出当前主机上的所有网络类型，从中选择合适的网络配置。</p><h3 style=\\\"-webkit-tap-highlight-color:transparent;margin:0;margin-top:30px;margin-bottom:15px;border-style:none;border-width:1px;border-color:rgb(0,0,0);border-radius:0;background-attachment:scroll;background-clip:border-box;background-image:url(https://mmbiz.qpic.cn/sz_mmbiz_png/bA6ibvWzutIZQE6MAqh3pAcTaICuVEgA6V17nSSNkBhZbiaj4azxSb6MYWYQEUGzw5FFq2iaK2nO6Twa8Y09DWL5A/640?wx_fmt=png&amp;from=appmsg);background-origin:padding-box;background-position:50% 50%;background-repeat:no-repeat;background-size:30px 30px;width:auto;height:auto;align-items:unset;box-shadow:none;display:flex;flex-direction:unset;float:unset;justify-content:center;line-height:1.5em;overflow:unset;text-shadow:none;transform:none;-webkit-box-reflect:unset\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:18px;color:rgb(43,43,43);line-height:2.4em;letter-spacing:0;margin-top:38px;margin-bottom:10px;align-items:unset;background-attachment:scroll;background-clip:border-box;background-image:none;background-origin:padding-box;background-position:0 0;background-repeat:no-repeat;background-size:auto;border-style:none;border-width:1px;border-color:rgb(0,0,0);border-radius:0;box-shadow:none;display:inline-block;font-weight:bold;flex-direction:unset;float:unset;height:38px;justify-content:unset;overflow:unset;text-align:center;text-indent:0;text-shadow:none;transform:none;width:auto;-webkit-box-reflect:unset\\\">限制网络带宽</span></h3><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;color:rgb(43,43,43);font-size:14px;line-height:1.8em;letter-spacing:0.02em;text-indent:0;padding-top:8px;padding-bottom:8px\\\">Docker 支持使用 --network-opt 设置自定义网络的带宽上限，帮助控制容器的网络带宽。对于共享资源的多租户系统，网络限速可以避免个别容器过度占用带宽，影响整体系统的稳定性。</p><pre style=\\\"-webkit-tap-highlight-color:transparent;border-radius:5px;box-shadow:rgba(0,0,0,0.55) 0 2px 10px;margin-top:10px;margin-bottom:10px\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;display:block;background:url(https://mmbiz.qpic.cn/mmbiz_svg/eHEMOF2hOelPPWBYXFCk1jia9ZXzQo1KF8wX9pTiaFJDNgF8sEkJ1sWhSvfC4Eb5MnOsGjeMq8l3d4BeypK0PVYBgicGYQBo6gM/640?wx_fmt=svg&amp;from=appmsg) 10px 10px/40px no-repeat rgb(40,44,52);height:30px;width:100%;margin-bottom:-7px;border-radius:5px\\\"></span><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\">docker network create \\\\<br style=\\\"-webkit-tap-highlight-color:transparent\\\"/>  --opt com.docker.network.driver.mtu=1200 \\\\<br style=\\\"-webkit-tap-highlight-color:transparent\\\"/>  --opt com.docker.network.window=30 \\\\<br style=\\\"-webkit-tap-highlight-color:transparent\\\"/>  custom_network<br style=\\\"-webkit-tap-highlight-color:transparent\\\"/></div></pre><h3 style=\\\"-webkit-tap-highlight-color:transparent;margin:0;margin-top:30px;margin-bottom:15px;border-style:none;border-width:1px;border-color:rgb(0,0,0);border-radius:0;background-attachment:scroll;background-clip:border-box;background-image:url(https://mmbiz.qpic.cn/sz_mmbiz_png/bA6ibvWzutIZQE6MAqh3pAcTaICuVEgA6V17nSSNkBhZbiaj4azxSb6MYWYQEUGzw5FFq2iaK2nO6Twa8Y09DWL5A/640?wx_fmt=png&amp;from=appmsg);background-origin:padding-box;background-position:50% 50%;background-repeat:no-repeat;background-size:30px 30px;width:auto;height:auto;align-items:unset;box-shadow:none;display:flex;flex-direction:unset;float:unset;justify-content:center;line-height:1.5em;overflow:unset;text-shadow:none;transform:none;-webkit-box-reflect:unset\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:18px;color:rgb(43,43,43);line-height:2.4em;letter-spacing:0;margin-top:38px;margin-bottom:10px;align-items:unset;background-attachment:scroll;background-clip:border-box;background-image:none;background-origin:padding-box;background-position:0 0;background-repeat:no-repeat;background-size:auto;border-style:none;border-width:1px;border-color:rgb(0,0,0);border-radius:0;box-shadow:none;display:inline-block;font-weight:bold;flex-direction:unset;float:unset;height:38px;justify-content:unset;overflow:unset;text-align:center;text-indent:0;text-shadow:none;transform:none;width:auto;-webkit-box-reflect:unset\\\">使用自定义 DNS 配置</span></h3><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;color:rgb(43,43,43);font-size:14px;line-height:1.8em;letter-spacing:0.02em;text-indent:0;padding-top:8px;padding-bottom:8px\\\">在微服务架构中，DNS 解析是容器间通信的关键。Docker 默认使用主机的 DNS 配置，但在某些情况下，配置自定义 DNS 服务器更可靠。使用 --dns 参数为容器指定 DNS 服务器，以确保解析过程不受主机配置影响。</p><pre style=\\\"-webkit-tap-highlight-color:transparent;border-radius:5px;box-shadow:rgba(0,0,0,0.55) 0 2px 10px;margin-top:10px;margin-bottom:10px\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;display:block;background:url(https://mmbiz.qpic.cn/mmbiz_svg/eHEMOF2hOelPPWBYXFCk1jia9ZXzQo1KF8wX9pTiaFJDNgF8sEkJ1sWhSvfC4Eb5MnOsGjeMq8l3d4BeypK0PVYBgicGYQBo6gM/640?wx_fmt=svg&amp;from=appmsg) 10px 10px/40px no-repeat rgb(40,44,52);height:30px;width:100%;margin-bottom:-7px;border-radius:5px\\\"></span><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\">docker run --dns 8.8.8.8 --dns 8.8.4.4 --network my-custom-network my_container<br style=\\\"-webkit-tap-highlight-color:transparent\\\"/></div></pre><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;color:rgb(43,43,43);font-size:14px;line-height:1.8em;letter-spacing:0.02em;text-indent:0;padding-top:8px;padding-bottom:8px\\\">也可以通过在 /etc/docker/daemon.json 文件中添加 &quot;dns&quot; 配置，设置 Docker Daemon 的默认 DNS。</p><pre style=\\\"-webkit-tap-highlight-color:transparent;border-radius:5px;box-shadow:rgba(0,0,0,0.55) 0 2px 10px;margin-top:10px;margin-bottom:10px\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;display:block;background:url(https://mmbiz.qpic.cn/mmbiz_svg/eHEMOF2hOelPPWBYXFCk1jia9ZXzQo1KF8wX9pTiaFJDNgF8sEkJ1sWhSvfC4Eb5MnOsGjeMq8l3d4BeypK0PVYBgicGYQBo6gM/640?wx_fmt=svg&amp;from=appmsg) 10px 10px/40px no-repeat rgb(40,44,52);height:30px;width:100%;margin-bottom:-7px;border-radius:5px\\\"></span><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\">{<br style=\\\"-webkit-tap-highlight-color:transparent\\\"/>  <span style=\\\"-webkit-tap-highlight-color:transparent;color:#98c379;line-height:26px\\\">&quot;dns&quot;</span>: [<span style=\\\"-webkit-tap-highlight-color:transparent;color:#98c379;line-height:26px\\\">&quot;8.8.8.8&quot;</span>, <span style=\\\"-webkit-tap-highlight-color:transparent;color:#98c379;line-height:26px\\\">&quot;8.8.4.4&quot;</span>]<br style=\\\"-webkit-tap-highlight-color:transparent\\\"/>}<br style=\\\"-webkit-tap-highlight-color:transparent\\\"/></div></pre><h3 style=\\\"-webkit-tap-highlight-color:transparent;margin:0;margin-top:30px;margin-bottom:15px;border-style:none;border-width:1px;border-color:rgb(0,0,0);border-radius:0;background-attachment:scroll;background-clip:border-box;background-image:url(https://mmbiz.qpic.cn/sz_mmbiz_png/bA6ibvWzutIZQE6MAqh3pAcTaICuVEgA6V17nSSNkBhZbiaj4azxSb6MYWYQEUGzw5FFq2iaK2nO6Twa8Y09DWL5A/640?wx_fmt=png&amp;from=appmsg);background-origin:padding-box;background-position:50% 50%;background-repeat:no-repeat;background-size:30px 30px;width:auto;height:auto;align-items:unset;box-shadow:none;display:flex;flex-direction:unset;float:unset;justify-content:center;line-height:1.5em;overflow:unset;text-shadow:none;transform:none;-webkit-box-reflect:unset\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:18px;color:rgb(43,43,43);line-height:2.4em;letter-spacing:0;margin-top:38px;margin-bottom:10px;align-items:unset;background-attachment:scroll;background-clip:border-box;background-image:none;background-origin:padding-box;background-position:0 0;background-repeat:no-repeat;background-size:auto;border-style:none;border-width:1px;border-color:rgb(0,0,0);border-radius:0;box-shadow:none;display:inline-block;font-weight:bold;flex-direction:unset;float:unset;height:38px;justify-content:unset;overflow:unset;text-align:center;text-indent:0;text-shadow:none;transform:none;width:auto;-webkit-box-reflect:unset\\\">网络命名空间隔离</span></h3><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;color:rgb(43,43,43);font-size:14px;line-height:1.8em;letter-spacing:0.02em;text-indent:0;padding-top:8px;padding-bottom:8px\\\">对于隔离要求高的应用，建议将生产和测试环境分别置于不同的网络命名空间。例如，您可以创建不同的自定义网络来隔离环境，确保敏感数据或服务不会意外暴露或被干扰。</p><h2 style=\\\"-webkit-tap-highlight-color:transparent;margin:0;border-color:rgb(0,0,0) rgb(0,0,0) rgb(64,184,250);margin-top:30px;margin-bottom:15px;align-items:unset;background-attachment:scroll;background-clip:border-box;background-image:none;background-origin:padding-box;background-position:0 0;background-repeat:no-repeat;background-size:auto;border-style:none none solid;border-width:1px 1px 4px;border-radius:0;box-shadow:none;flex-direction:unset;float:unset;height:auto;justify-content:unset;line-height:1.5em;overflow:unset;text-shadow:none;transform:none;width:auto;-webkit-box-reflect:unset\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;background-attachment:scroll;background-clip:border-box;background-image:url(https://mmbiz.qpic.cn/sz_mmbiz_png/bA6ibvWzutIZQE6MAqh3pAcTaICuVEgA6ERpC8WHMy8YFs9MMyYiapbY5qstAkqw21ib3KmPwJF9UqHjnibMfa6e1g/640?wx_fmt=png&amp;from=appmsg);background-origin:padding-box;background-position:0 0;background-repeat:no-repeat;background-size:20px 20px;width:20px;height:20px;align-items:unset;border-style:none;border-width:1px;border-color:rgb(0,0,0);border-radius:0;box-shadow:none;display:flex;font-size:22px;font-weight:bold;flex-direction:unset;float:unset;justify-content:unset;letter-spacing:0;line-height:1.5em;margin-bottom:-25px;overflow:unset;text-indent:0;text-shadow:none;transform:none;-webkit-box-reflect:unset\\\"></span><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:20px;color:rgb(64,184,250);line-height:1.5em;letter-spacing:0;align-items:unset;background-attachment:scroll;background-clip:border-box;background-image:none;background-origin:padding-box;background-position:0 0;background-repeat:no-repeat;background-size:auto;border-style:none;border-width:1px;border-color:rgb(0,0,0);border-radius:0;box-shadow:none;display:flex;font-weight:bold;flex-direction:unset;float:unset;height:auto;justify-content:unset;margin-left:25px;overflow:unset;text-indent:0;text-shadow:none;transform:none;width:auto;-webkit-box-reflect:unset\\\">4. Docker 网络常见问题</span><span style=\\\"-webkit-tap-highlight-color:transparent;background:none 0 0/auto no-repeat scroll padding-box border-box rgba(64,184,250,0.5);align-items:unset;border-style:none;border-width:1px;border-color:rgb(0,0,0);border-radius:20px 0 0;box-shadow:none;display:flex;font-size:22px;font-weight:bold;flex-direction:unset;float:right;height:10px;justify-content:unset;letter-spacing:0;line-height:1.5em;margin-top:-10px;overflow:unset;text-indent:0;text-shadow:none;transform:none;width:200px;-webkit-box-reflect:unset\\\"></span></h2><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;color:rgb(43,43,43);font-size:14px;line-height:1.8em;letter-spacing:0.02em;text-indent:0;padding-top:8px;padding-bottom:8px\\\">在使用 Docker 网络时，开发者可能会遇到一些常见问题。以下列出几种常见问题及对应的解决方案。</p><h3 style=\\\"-webkit-tap-highlight-color:transparent;margin:0;margin-top:30px;margin-bottom:15px;border-style:none;border-width:1px;border-color:rgb(0,0,0);border-radius:0;background-attachment:scroll;background-clip:border-box;background-image:url(https://mmbiz.qpic.cn/sz_mmbiz_png/bA6ibvWzutIZQE6MAqh3pAcTaICuVEgA6V17nSSNkBhZbiaj4azxSb6MYWYQEUGzw5FFq2iaK2nO6Twa8Y09DWL5A/640?wx_fmt=png&amp;from=appmsg);background-origin:padding-box;background-position:50% 50%;background-repeat:no-repeat;background-size:30px 30px;width:auto;height:auto;align-items:unset;box-shadow:none;display:flex;flex-direction:unset;float:unset;justify-content:center;line-height:1.5em;overflow:unset;text-shadow:none;transform:none;-webkit-box-reflect:unset\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:18px;color:rgb(43,43,43);line-height:2.4em;letter-spacing:0;margin-top:38px;margin-bottom:10px;align-items:unset;background-attachment:scroll;background-clip:border-box;background-image:none;background-origin:padding-box;background-position:0 0;background-repeat:no-repeat;background-size:auto;border-style:none;border-width:1px;border-color:rgb(0,0,0);border-radius:0;box-shadow:none;display:inline-block;font-weight:bold;flex-direction:unset;float:unset;height:38px;justify-content:unset;overflow:unset;text-align:center;text-indent:0;text-shadow:none;transform:none;width:auto;-webkit-box-reflect:unset\\\">问题 1：容器之间无法通信</span></h3><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;color:rgb(43,43,43);font-size:14px;line-height:1.8em;letter-spacing:0.02em;text-indent:0;padding-top:8px;padding-bottom:8px\\\">原因：容器未连接到同一个网络，或网络配置不当。</p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;color:rgb(43,43,43);font-size:14px;line-height:1.8em;letter-spacing:0.02em;text-indent:0;padding-top:8px;padding-bottom:8px\\\">解决方案：确保容器位于相同的自定义网络上，可通过 <code style=\\\"-webkit-tap-highlight-color:transparent;color:rgb(53,148,247);line-height:1.8em;letter-spacing:0;background:none 0 0/auto no-repeat scroll padding-box border-box rgba(27,31,35,0.05);width:auto;height:auto;margin-left:2px;margin-right:2px;padding:2px 4px;border-style:none;border-width:3px;border-color:rgb(0,0,0) rgba(0,0,0,0.4) rgba(0,0,0,0.4);border-radius:4px;font-family:&quot;Operator Mono&quot;,Consolas,Monaco,Menlo,monospace;word-break:break-all\\\">docker network connect</code> 将容器添加到目标网络，或使用自定义网络创建容器。检查 <code style=\\\"-webkit-tap-highlight-color:transparent;color:rgb(53,148,247);line-height:1.8em;letter-spacing:0;background:none 0 0/auto no-repeat scroll padding-box border-box rgba(27,31,35,0.05);width:auto;height:auto;margin-left:2px;margin-right:2px;padding:2px 4px;border-style:none;border-width:3px;border-color:rgb(0,0,0) rgba(0,0,0,0.4) rgba(0,0,0,0.4);border-radius:4px;font-family:&quot;Operator Mono&quot;,Consolas,Monaco,Menlo,monospace;word-break:break-all\\\">docker network inspect &lt;network_name&gt;</code>，查看是否所有容器均正确连接。</p><pre style=\\\"-webkit-tap-highlight-color:transparent;border-radius:5px;box-shadow:rgba(0,0,0,0.55) 0 2px 10px;margin-top:10px;margin-bottom:10px\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;display:block;background:url(https://mmbiz.qpic.cn/mmbiz_svg/eHEMOF2hOelPPWBYXFCk1jia9ZXzQo1KF8wX9pTiaFJDNgF8sEkJ1sWhSvfC4Eb5MnOsGjeMq8l3d4BeypK0PVYBgicGYQBo6gM/640?wx_fmt=svg&amp;from=appmsg) 10px 10px/40px no-repeat rgb(40,44,52);height:30px;width:100%;margin-bottom:-7px;border-radius:5px\\\"></span><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\">docker network connect my-custom-network container1<br style=\\\"-webkit-tap-highlight-color:transparent\\\"/></div></pre><h3 style=\\\"-webkit-tap-highlight-color:transparent;margin:0;margin-top:30px;margin-bottom:15px;border-style:none;border-width:1px;border-color:rgb(0,0,0);border-radius:0;background-attachment:scroll;background-clip:border-box;background-image:url(https://mmbiz.qpic.cn/sz_mmbiz_png/bA6ibvWzutIZQE6MAqh3pAcTaICuVEgA6V17nSSNkBhZbiaj4azxSb6MYWYQEUGzw5FFq2iaK2nO6Twa8Y09DWL5A/640?wx_fmt=png&amp;from=appmsg);background-origin:padding-box;background-position:50% 50%;background-repeat:no-repeat;background-size:30px 30px;width:auto;height:auto;align-items:unset;box-shadow:none;display:flex;flex-direction:unset;float:unset;justify-content:center;line-height:1.5em;overflow:unset;text-shadow:none;transform:none;-webkit-box-reflect:unset\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:18px;color:rgb(43,43,43);line-height:2.4em;letter-spacing:0;margin-top:38px;margin-bottom:10px;align-items:unset;background-attachment:scroll;background-clip:border-box;background-image:none;background-origin:padding-box;background-position:0 0;background-repeat:no-repeat;background-size:auto;border-style:none;border-width:1px;border-color:rgb(0,0,0);border-radius:0;box-shadow:none;display:inline-block;font-weight:bold;flex-direction:unset;float:unset;height:38px;justify-content:unset;overflow:unset;text-align:center;text-indent:0;text-shadow:none;transform:none;width:auto;-webkit-box-reflect:unset\\\">问题 2：桥接网络内通信不通</span></h3><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;color:rgb(43,43,43);font-size:14px;line-height:1.8em;letter-spacing:0.02em;text-indent:0;padding-top:8px;padding-bottom:8px\\\">原因：默认桥接网络或防火墙阻止了容器间通信。</p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;color:rgb(43,43,43);font-size:14px;line-height:1.8em;letter-spacing:0.02em;text-indent:0;padding-top:8px;padding-bottom:8px\\\">解决方案：使用 docker network inspect bridge 检查网络设置，确保桥接网络的设置未被更改。如果网络仍不通，可能需要检查主机防火墙规则，确保允许 Docker 的默认端口和 IP 范围。</p><h3 style=\\\"-webkit-tap-highlight-color:transparent;margin:0;margin-top:30px;margin-bottom:15px;border-style:none;border-width:1px;border-color:rgb(0,0,0);border-radius:0;background-attachment:scroll;background-clip:border-box;background-image:url(https://mmbiz.qpic.cn/sz_mmbiz_png/bA6ibvWzutIZQE6MAqh3pAcTaICuVEgA6V17nSSNkBhZbiaj4azxSb6MYWYQEUGzw5FFq2iaK2nO6Twa8Y09DWL5A/640?wx_fmt=png&amp;from=appmsg);background-origin:padding-box;background-position:50% 50%;background-repeat:no-repeat;background-size:30px 30px;width:auto;height:auto;align-items:unset;box-shadow:none;display:flex;flex-direction:unset;float:unset;justify-content:center;line-height:1.5em;overflow:unset;text-shadow:none;transform:none;-webkit-box-reflect:unset\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:18px;color:rgb(43,43,43);line-height:2.4em;letter-spacing:0;margin-top:38px;margin-bottom:10px;align-items:unset;background-attachment:scroll;background-clip:border-box;background-image:none;background-origin:padding-box;background-position:0 0;background-repeat:no-repeat;background-size:auto;border-style:none;border-width:1px;border-color:rgb(0,0,0);border-radius:0;box-shadow:none;display:inline-block;font-weight:bold;flex-direction:unset;float:unset;height:38px;justify-content:unset;overflow:unset;text-align:center;text-indent:0;text-shadow:none;transform:none;width:auto;-webkit-box-reflect:unset\\\">问题 3：服务端口映射失败</span></h3><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;color:rgb(43,43,43);font-size:14px;line-height:1.8em;letter-spacing:0.02em;text-indent:0;padding-top:8px;padding-bottom:8px\\\">原因：容器内服务未绑定到正确的 IP 或端口映射未设置。</p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;color:rgb(43,43,43);font-size:14px;line-height:1.8em;letter-spacing:0.02em;text-indent:0;padding-top:8px;padding-bottom:8px\\\">解决方案：确保服务监听 0.0.0.0，而非 localhost。启动容器时使用 -p 参数设置端口映射，如 docker run -d -p 8080:80 my_container。</p><hr style=\\\"-webkit-tap-highlight-color:transparent;margin-top:10px;margin-bottom:10px;border-style:solid none none;border-width:2px 3px 3px;border-color:rgb(59,170,250) rgba(0,0,0,0.4) rgba(0,0,0,0.4);border-radius:0;background-attachment:scroll;background-clip:border-box;background-image:none;background-origin:padding-box;background-position:0 0;background-repeat:no-repeat;background-size:auto;width:auto;height:1px\\\"/><h2 style=\\\"-webkit-tap-highlight-color:transparent;margin:0;border-color:rgb(0,0,0) rgb(0,0,0) rgb(64,184,250);margin-top:30px;margin-bottom:15px;align-items:unset;background-attachment:scroll;background-clip:border-box;background-image:none;background-origin:padding-box;background-position:0 0;background-repeat:no-repeat;background-size:auto;border-style:none none solid;border-width:1px 1px 4px;border-radius:0;box-shadow:none;flex-direction:unset;float:unset;height:auto;justify-content:unset;line-height:1.5em;overflow:unset;text-shadow:none;transform:none;width:auto;-webkit-box-reflect:unset\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;background-attachment:scroll;background-clip:border-box;background-image:url(https://mmbiz.qpic.cn/sz_mmbiz_png/bA6ibvWzutIZQE6MAqh3pAcTaICuVEgA6ERpC8WHMy8YFs9MMyYiapbY5qstAkqw21ib3KmPwJF9UqHjnibMfa6e1g/640?wx_fmt=png&amp;from=appmsg);background-origin:padding-box;background-position:0 0;background-repeat:no-repeat;background-size:20px 20px;width:20px;height:20px;align-items:unset;border-style:none;border-width:1px;border-color:rgb(0,0,0);border-radius:0;box-shadow:none;display:flex;font-size:22px;font-weight:bold;flex-direction:unset;float:unset;justify-content:unset;letter-spacing:0;line-height:1.5em;margin-bottom:-25px;overflow:unset;text-indent:0;text-shadow:none;transform:none;-webkit-box-reflect:unset\\\"></span><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:20px;color:rgb(64,184,250);line-height:1.5em;letter-spacing:0;align-items:unset;background-attachment:scroll;background-clip:border-box;background-image:none;background-origin:padding-box;background-position:0 0;background-repeat:no-repeat;background-size:auto;border-style:none;border-width:1px;border-color:rgb(0,0,0);border-radius:0;box-shadow:none;display:flex;font-weight:bold;flex-direction:unset;float:unset;height:auto;justify-content:unset;margin-left:25px;overflow:unset;text-indent:0;text-shadow:none;transform:none;width:auto;-webkit-box-reflect:unset\\\">结论</span><span style=\\\"-webkit-tap-highlight-color:transparent;background:none 0 0/auto no-repeat scroll padding-box border-box rgba(64,184,250,0.5);align-items:unset;border-style:none;border-width:1px;border-color:rgb(0,0,0);border-radius:20px 0 0;box-shadow:none;display:flex;font-size:22px;font-weight:bold;flex-direction:unset;float:right;height:10px;justify-content:unset;letter-spacing:0;line-height:1.5em;margin-top:-10px;overflow:unset;text-indent:0;text-shadow:none;transform:none;width:200px;-webkit-box-reflect:unset\\\"></span></h2><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;color:rgb(43,43,43);font-size:14px;line-height:1.8em;letter-spacing:0.02em;text-indent:0;padding-top:8px;padding-bottom:8px\\\">Docker 网络是一个强大的功能，允许容器与彼此和外部世界无缝交互。通过了解不同的 Docker 网络类型以及如何配置它们，开发者可以高效地构建和部署容器化应用程序。无论您是在开发一个小型应用程序还是复杂的多容器系统，Docker 网络都能实现这一切。</p></div><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><br style=\\\"-webkit-tap-highlight-color:transparent\\\"/></p></div></div></div></div></div></span>\\\n</div></body></html>\\u0000\"]],\"start1\":0,\"start2\":0,\"length1\":0,\"length2\":69480}]"
metadata_diff: {"new":{"id":"a5f75cc2a5bc4f31ab7cf0e99240bceb","parent_id":"f67288c3a0be4374b5d532b5dcc3aabc","latitude":"0.00000000","longitude":"0.00000000","altitude":"0.0000","author":"","source_url":"","is_todo":0,"todo_due":0,"todo_completed":0,"source":"joplin-desktop","source_application":"net.cozic.joplin-desktop","application_data":"","order":1764348818421,"markup_language":2,"is_shared":0,"share_id":"","conflict_original_id":"","master_key_id":"","user_data":"","deleted_time":0},"deleted":[]}
encryption_cipher_text: 
encryption_applied: 0
updated_time: 2025-11-28T21:03:25.667Z
created_time: 2025-11-28T21:03:25.667Z
type_: 13