{"id":340,"date":"2025-07-11T23:13:16","date_gmt":"2025-07-11T15:13:16","guid":{"rendered":"https:\/\/www.xxiaoteng.cn\/?p=340"},"modified":"2026-05-11T21:23:01","modified_gmt":"2026-05-11T13:23:01","slug":"docker%e7%bd%91%e7%bb%9c","status":"publish","type":"post","link":"https:\/\/www.xxiaoteng.cn\/?p=340","title":{"rendered":"DOCKER\u7f51\u7edc"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\" id=\"toc-0\">\u4e00\u3001Docker \u7f51\u7edc<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">docker\u7f51\u7edc\u4e3b\u8981\u662f\u89e3\u51b3\u5bb9\u5668\u8054\u7f51\u95ee\u9898\uff0c\u4e5f\u662f\u6211\u4eec\u4f7f\u7528\u5bb9\u5668\u4e2d\u6700\u91cd\u8981\u7684\u4e00\u4e2a\u73af\u8282\uff0c\u5982\u679c\u5bb9\u5668\u6ca1\u6709\u7f51\u7edc\u5219\u65e0\u6cd5\u5411\u7f51\u7edc\u4e2d\u63d0\u4f9b\u670d\u52a1\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-1\">\u7f51\u7edc\u7ba1\u7406\u547d\u4ee4\uff1adocker network<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">[root@wing ~]# docker network --help<br>\u200b<br>Usage:  docker network COMMAND<br>\u200b<br>Manage networks<br>\u200b<br>Commands:<br>  connect &nbsp; &nbsp; Connect a container to a network<br>  create &nbsp; &nbsp;  Create a network<br>  disconnect  Disconnect a container from a network<br>  inspect &nbsp; &nbsp; Display detailed information on one or more networks<br>  ls &nbsp; &nbsp; &nbsp; &nbsp;  List networks<br>  prune &nbsp; &nbsp; &nbsp; Remove all unused networks<br>  rm &nbsp; &nbsp; &nbsp; &nbsp;  Remove one or more networks<br>\u200b<br>Run 'docker network COMMAND --help' for more information on a command.<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"toc-2\">\u4e8c\u3001docker\u7f51\u7edc\u7c7b\u578b<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">\u521b\u5efa\u5bb9\u5668\u7684\u65f6\u5019\u53ef\u4ee5\u901a\u8fc7\u2014network\u547d\u4ee4\u6765\u6307\u5b9a\u5bb9\u5668\u7684\u7f51\u7edc\uff0c\u7f51\u7edc\u7c7b\u578b\u6709\u4ee5\u4e0b\u56db\u79cd<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>bridge<\/li>\n\n\n\n<li>host<\/li>\n\n\n\n<li>none<\/li>\n\n\n\n<li>\u5bb9\u5668\u7f51\u7edc\u6216\u8054\u76df\u7f51\u7edc<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-3\">bridge<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u6865\u63a5\u7f51\u7edc\u662f\u6307\u5bb9\u5668\u901a\u8fc7\u6865\u63a5\u7684\u65b9\u5f0f\u5c06\u5bb9\u5668\u7f51\u5361\u6865\u63a5\u5230\u5bbf\u4e3b\u673a\u7684docker0\u7f51\u6865\uff0c\u7136\u540e\u5728\u901a\u8fc7\u5bbf\u4e3b\u673a\u9632\u706b\u5899\u7684NAT\u8868\u5b9e\u73b0\u4e0e\u5916\u7f51\u7684\u8054\u7cfb\u3002<\/p>\n\n\n\n<h5 class=\"wp-block-heading\" id=\"toc-4\">\u5bbf\u4e3b\u673adocker0\u7f51\u6865<\/h5>\n\n\n\n<pre class=\"wp-block-preformatted\">[root@wing ~]# ifconfig <br>#docker0\u7f51\u6865<br>docker0: flags=4163&lt;UP,BROADCAST,RUNNING,MULTICAST&gt;  mtu 1500<br> &nbsp; &nbsp; &nbsp;  inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255<br> &nbsp; &nbsp; &nbsp;  inet6 fe80::42:c7ff:fe37:8e8  prefixlen 64  scopeid 0x20&lt;link&gt;<br> &nbsp; &nbsp; &nbsp;  ether 02:42:c7:37:08:e8  txqueuelen 0  (Ethernet)<br> &nbsp; &nbsp; &nbsp;  RX packets 6618  bytes 277975 (271.4 KiB)<br> &nbsp; &nbsp; &nbsp;  RX errors 0  dropped 0  overruns 0  frame 0<br> &nbsp; &nbsp; &nbsp;  TX packets 8152  bytes 24675021 (23.5 MiB)<br> &nbsp; &nbsp; &nbsp;  TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0<br>\u200b<br>.....\u7701\u7565\u4e86\u672c\u673a\u7684\u7f51\u5361\u4fe1\u606f<br>#\u5bb9\u5668\u7f51\u5361\uff0c\u6bcf\u521b\u5efa\u4e00\u4e2a\u6865\u63a5\u7f51\u7edc\u7684\u5bb9\u5668\u5c31\u4f1a\u751f\u6210\u4e00\u4e2a\u5bf9\u5e94\u7684\u7f51\u5361<br>vethf75a942: flags=4163&lt;UP,BROADCAST,RUNNING,MULTICAST&gt;  mtu 1500<br> &nbsp; &nbsp; &nbsp;  inet6 fe80::9085:f5ff:fe34:77b5  prefixlen 64  scopeid 0x20&lt;link&gt;<br> &nbsp; &nbsp; &nbsp;  ether 92:85:f5:34:77:b5  txqueuelen 0  (Ethernet)<br> &nbsp; &nbsp; &nbsp;  RX packets 2850  bytes 158484 (154.7 KiB)<br> &nbsp; &nbsp; &nbsp;  RX errors 0  dropped 0  overruns 0  frame 0<br> &nbsp; &nbsp; &nbsp;  TX packets 3397  bytes 11613136 (11.0 MiB)<br> &nbsp; &nbsp; &nbsp;  TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0<br> &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp;<br>\u5982\u679c\u60f3\u770b\u66f4\u6e05\u695a\u4e00\u4e0b  \u53ef\u4ee5\u4f7f\u7528  ip  add  show\u547d\u4ee4<br>[root@wing ~]# ip add show<br>\u200b<br>4: docker0: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1500 qdisc noqueue state UP group default <br> &nbsp;  link\/ether 02:42:c7:37:08:e8 brd ff:ff:ff:ff:ff:ff<br> &nbsp;  inet 172.17.0.1\/16 brd 172.17.255.255 scope global docker0<br> &nbsp; &nbsp; &nbsp; valid_lft forever preferred_lft forever<br> &nbsp;  inet6 fe80::42:c7ff:fe37:8e8\/64 scope link <br> &nbsp; &nbsp; &nbsp; valid_lft forever preferred_lft forever<br>\u200b<br>\u5bb9\u5668\u7f51\u5361<br>14: vethf75a942@if13: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1500 qdisc noqueue master docker0 state UP group default <br> &nbsp;  link\/ether 92:85:f5:34:77:b5 brd ff:ff:ff:ff:ff:ff link-netnsid 1<br> &nbsp;  inet6 fe80::9085:f5ff:fe34:77b5\/64 scope link <br> &nbsp; &nbsp; &nbsp; valid_lft forever preferred_lft forever<br>\u200b<br>\u200b<br>\u6ce8\u610f\uff1a<br>\u8fd9\u91cc\u7684vethf75a942@if13\u6307\u7684\u5c31\u662f\u5bb9\u5668\u7f51\u5361\uff0cV\u4ee3\u8868\u865a\u62df\u7f51\u5361\u7684\u610f\u601d\uff0ceth \u4ee5\u592a\u7f51\u5361\uff0cf75a942\u7f51\u5361\u7f16\u53f7\uff0cif13\u6307\u7684\u662f\u5bbf\u4e3b\u673a\u7f51\u6865(docekr0)\u7684\u4e00\u4e2a\u7aef\u53e3\uff0c\u5bf9\u5e94\u5bb9\u5668\u7684\u7f51\u5361\u7f16\u53f7\u52a0\u4e00\u3002<br>\u6240\u4ee5\u5bb9\u5668\u5185\u7684\u7f51\u5361\u7f16\u53f7\u5e94\u8be5\u662f eth0@if14<br>\u200b<br>\u901a\u8fc7\u5728\u5bb9\u5668\u4e2d\u6267\u884c\u547d\u4ee4  ip add show \u4e5f\u53ef\u4ee5\u770b\u5230<br>[root@wing ~]# docker exec centos1 ip add show<br>1: lo: &lt;LOOPBACK,UP,LOWER_UP&gt; mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000<br> &nbsp;  link\/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00<br> &nbsp;  inet 127.0.0.1\/8 scope host lo<br> &nbsp; &nbsp; &nbsp; valid_lft forever preferred_lft forever<br>13: eth0@if14: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1500 qdisc noqueue state UP group default <br> &nbsp;  link\/ether 02:42:ac:11:00:03 brd ff:ff:ff:ff:ff:ff link-netnsid 0<br> &nbsp;  inet 172.17.0.3\/16 brd 172.17.255.255 scope global eth0<br> &nbsp; &nbsp; &nbsp; valid_lft forever preferred_lft forever<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-5\">\u9632\u706b\u5899\u7684NAT\u8868\u5185\u5bb9<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">[root@wing ~]# iptables -t nat -L<br>Chain PREROUTING (policy ACCEPT)<br>target &nbsp; &nbsp; prot opt source &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; destination &nbsp; &nbsp; &nbsp; &nbsp; <br>DOCKER &nbsp; &nbsp; all  --  anywhere &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; anywhere &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ADDRTYPE match dst-type LOCAL<br>\u200b<br>Chain INPUT (policy ACCEPT)<br>target &nbsp; &nbsp; prot opt source &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; destination &nbsp; &nbsp; &nbsp; &nbsp; <br>\u200b<br>Chain OUTPUT (policy ACCEPT)<br>target &nbsp; &nbsp; prot opt source &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; destination &nbsp; &nbsp; &nbsp; &nbsp; <br>DOCKER &nbsp; &nbsp; all  --  anywhere &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  !loopback\/8 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ADDRTYPE match dst-type LOCAL<br>\u200b<br>Chain POSTROUTING (policy ACCEPT)<br>target &nbsp; &nbsp; prot opt source &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; destination &nbsp; &nbsp; &nbsp; &nbsp; <br>MASQUERADE  all  --  172.17.0.0\/16 &nbsp; &nbsp; &nbsp;  anywhere &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>\u200b<br>Chain DOCKER (2 references)<br>target &nbsp; &nbsp; prot opt source &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; destination &nbsp; &nbsp; &nbsp; &nbsp; <br>RETURN &nbsp; &nbsp; all  --  anywhere &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; anywhere &nbsp; &nbsp; &nbsp; &nbsp;<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-6\">docker0 \u4e0e\u5bb9\u5668\u7f51\u5361\u6865\u63a5<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">\u901a\u8fc7brctl show\u547d\u4ee4\u53ef\u4ee5\u770b\u5230\u5bb9\u5668\u7f51\u5361\u548cdocker0\u7f51\u5361\u7684\u6865\u63a5\u4fe1\u606f<br>[root@wing ~]# brctl show<br>bridge name bridge id       STP enabled interfaces<br>docker0     8000.0242c73708e8   no      vethf75a942<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u521b\u5efa\u4e00\u4e2a\u7f51\u7edc\u4e3abridge\u7c7b\u578b\u7684\u5bb9\u5668\uff0c\u4e0d\u6307\u5b9a\u9ed8\u8ba4\u4e5f\u662f\u8fd9\u4e2a\u7c7b\u578b<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[root@wing ~]# docker run -d --network bridge --name centos1 baishuming2020\/centos_nginx<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-7\">host<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5bb9\u5668\u548c\u771f\u673a\u5171\u7528\u7f51\u5361\u53ca\u5bf9\u5e94\u7684\u7aef\u53e3\uff0c\u7f3a\u70b9\u5c31\u662f\u540c\u4e00\u4e2a\u7aef\u53e3\u53ea\u80fd\u5bbf\u4e3b\u673a\u6216\u8005\u67d0\u4e2a\u5bb9\u5668\u4f7f\u7528\uff0c\u5176\u4ed6\u5bb9\u5668\u4e0d\u80fd\u7528\u3002<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\u521b\u5efa\u4e00\u4e2a\u7f51\u7edc\u7c7b\u578bhost\u7684\u5bb9\u5668<br>[root@wing ~]# docker run -d --network host --name centos2 baishuming2020\/centos_nginx<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-8\">none<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5bb9\u5668\u4ec5\u6709lo\u7f51\u5361\uff0c\u662f\u4e00\u4e2a\u4e0d\u80fd\u8054\u7f51\u7684\u672c\u5730\u5bb9\u5668<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\u521b\u5efa\u4e00\u4e2a\u7f51\u7edc\u7c7b\u578b\u4e3alo\u7684\u5bb9\u5668<br>[root@wing ~]# docker run -d --network none --name centos3 baishuming2020\/centos_nginx<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-9\">2.1\u3001\u5b9e\u73b0\u7f51\u6865\u7f51\u7edc<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u76ee\u7684\uff1a\u4e0d\u540c\u7684\u670d\u52a1\u5bb9\u5668\u7ec4\u5e94\u7528\u4e0d\u540c\u7684\u7f51\u6865\uff0c\u907f\u514d\u540c\u4e00\u7f51\u7edc\u5185\u5bb9\u5668\u592a\u591a\uff0c\u4fdd\u6301\u5bb9\u5668\u7f51\u7edc\u72ec\u7acb\u6027\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5173\u4e8e\u65b0\u7f51\u6865\u8054\u7f51\u95ee\u9898\uff1a\u521b\u5efa\u7f51\u6865\u540e\uff0c\u5bbf\u4e3b\u673a\u4f1a\u81ea\u52a8\u5e2e\u4f60\u505aNAT\uff0c\u6240\u4ee5\u4e0d\u7528\u62c5\u5fc3\u8054\u7f51\u95ee\u9898<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"toc-10\">\u67e5\u770b\u7f51\u7edc-ls<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">[root@wing ~]# docker network ls<br>NETWORK ID &nbsp; &nbsp; &nbsp; &nbsp;  NAME &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  DRIVER &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  SCOPE<br>80982d2613cd &nbsp; &nbsp; &nbsp;  bridge &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  bridge &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  local<br>40c179ab420a &nbsp; &nbsp; &nbsp;  docker1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bridge &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  local<br>04aadb7475c0 &nbsp; &nbsp; &nbsp;  docker100 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bridge &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  local<br>ce79e9d7525a &nbsp; &nbsp; &nbsp;  host &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  host &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  local<br>8f0358469e57 &nbsp; &nbsp; &nbsp;  none &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  null &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  local<br>\u200b<br>NETWORK ID &nbsp; &nbsp; \u7f51\u6865ID &nbsp; <br>NAME &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \u540d\u79f0<br>DRIVER &nbsp; &nbsp; &nbsp; &nbsp; \u7f51\u7edc\u7c7b\u578b &nbsp;<br>SCOPE                    \u4f5c\u7528\u8303\u56f4<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"toc-11\">\u521b\u5efa\u7f51\u6865-create<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">[root@wing ~]# docker network create -d bridge --subnet 192.168.1.0\/24 --gateway 192.168.1.1 mydocker0<br>6a410e27b66ea587142d967f7dff6f36c04ced3c27116a79831412f3743aba56<br>\u200b<br>[root@wing ~]# docker network ls<br>NETWORK ID &nbsp; &nbsp; &nbsp; &nbsp;  NAME &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  DRIVER &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  SCOPE<br>6ee1e928b710 &nbsp; &nbsp; &nbsp;  bridge &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  bridge &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  local<br>ce79e9d7525a &nbsp; &nbsp; &nbsp;  host &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  host &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  local<br>6a410e27b66e &nbsp; &nbsp; &nbsp;  mydocker0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bridge &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  local<br>8f0358469e57 &nbsp; &nbsp; &nbsp;  none &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  null &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  local<br>\u200b<br>\u200b<br>\u4fee\u6539docker\u7f51\u6865\u540d\u5b57<br>1\u3001\u5173\u95ed\u65b0\u5efa\u7f51\u6865<br>[root@wing ~]# ip link set dev br-6a410e27b66e down<br>2\u3001\u4fee\u6539\u540d\u5b57<br>[root@wing ~]# ip link set dev br-6a410e27b66e name  mydocker0<br>3\u3001\u542f\u52a8\u7f51\u6865<br>[root@wing ~]# ip link set dev mydocker0 up<br>4\u3001\u91cd\u542fdocker\u670d\u52a1<br>[root@wing ~]# systemctl restart docker<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"toc-12\">\u5220\u9664\u672a\u4f7f\u7528\u7684\u7f51\u6865-prune<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">[root@wing ~]# docker network prune <br>WARNING! This will remove all networks not used by at least one container.<br>Are you sure you want to continue? [y\/N] y<br>Deleted Networks:<br>docker1<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"toc-13\">\u5220\u9664\u67d0\u4e2a\u7f51\u6865-rm<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">[root@wing ~]# docker network rm docker100<br>docker100<br>\u200b<br>\u6ce8\u610f\uff1a<br>\u4e0d\u80fd\u88ab\u6d3b\u52a8\u5bb9\u5668\u5360\u7528<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"toc-14\">\u5bb9\u5668\u8fde\u63a5\u5230\u7f51\u6865<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u524d\u63d0\u662f\u8be5\u5bb9\u5668\u662f\u6865\u63a5\u7f51\u7edc<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[root@wing ~]# docker network connect docker1 centos1<br>[root@wing ~]# docker exec centos1 ifconfig<br>eth0: flags=4163&lt;UP,BROADCAST,RUNNING,MULTICAST&gt;  mtu 1500<br> &nbsp; &nbsp; &nbsp;  inet 172.17.0.2  netmask 255.255.0.0  broadcast 172.17.255.255<br> &nbsp; &nbsp; &nbsp;  ether 02:42:ac:11:00:02  txqueuelen 0  (Ethernet)<br> &nbsp; &nbsp; &nbsp;  RX packets 8  bytes 656 (656.0 B)<br> &nbsp; &nbsp; &nbsp;  RX errors 0  dropped 0  overruns 0  frame 0<br> &nbsp; &nbsp; &nbsp;  TX packets 0  bytes 0 (0.0 B)<br> &nbsp; &nbsp; &nbsp;  TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0<br>\u53d1\u73b0centos1\u5bb9\u5668\u591a\u4e86\u4e00\u5757\u7f51\u5361\uff0c\u4f7f\u7528\u7684\u6b63\u662fdocker1\u7684\u7f51\u6bb5<br>eth1: flags=4163&lt;UP,BROADCAST,RUNNING,MULTICAST&gt;  mtu 1500<br> &nbsp; &nbsp; &nbsp;  inet 192.168.1.2  netmask 255.255.255.0  broadcast 192.168.1.255<br> &nbsp; &nbsp; &nbsp;  ether 02:42:c0:a8:01:02  txqueuelen 0  (Ethernet)<br> &nbsp; &nbsp; &nbsp;  RX packets 16  bytes 1312 (1.2 KiB)<br> &nbsp; &nbsp; &nbsp;  RX errors 0  dropped 0  overruns 0  frame 0<br> &nbsp; &nbsp; &nbsp;  TX packets 0  bytes 0 (0.0 B)<br> &nbsp; &nbsp; &nbsp;  TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0<br>\u200b<br>lo: flags=73&lt;UP,LOOPBACK,RUNNING&gt;  mtu 65536<br> &nbsp; &nbsp; &nbsp;  inet 127.0.0.1  netmask 255.0.0.0<br> &nbsp; &nbsp; &nbsp;  loop  txqueuelen 1000  (Local Loopback)<br> &nbsp; &nbsp; &nbsp;  RX packets 0  bytes 0 (0.0 B)<br> &nbsp; &nbsp; &nbsp;  RX errors 0  dropped 0  overruns 0  frame 0<br> &nbsp; &nbsp; &nbsp;  TX packets 0  bytes 0 (0.0 B)<br> &nbsp; &nbsp; &nbsp;  TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"toc-15\">\u5bb9\u5668\u65ad\u5f00\u7f51\u6865<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">\u5c06centos1\u5bb9\u5668\u7684\u7f51\u7edc\u4ecedocker1\u7f51\u6865\u65ad\u5f00<br>[root@wing ~]# docker network disconnect docker1 centos1<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-16\">\u5e38\u89c1\u6545\u969c<\/h3>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-17\">FAQ1\uff1a\u4f7f\u7528\u6539\u540d\u540e\u7684\u65b0\u7f51\u6865\u7684\u5bb9\u5668\u53ef\u80fd\u65e0\u6cd5\u89e3\u6790\u57df\u540d<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u539f\u56e0\uff1a\u6ca1\u6709\u914d\u7f6e\u65b0\u7f51\u6865\u7684DNS<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u89e3\u51b3\u65b9\u6cd5\uff1a\u4e3a\u5bb9\u5668\u624b\u52a8\u914d\u7f6e\u4e00\u4e2aDNS\u5730\u5740\u5373\u53ef<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-18\">FAQ2\uff1aNetworking will not work<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">[root@wing ~]# docker run -d --network docker100 --name centos4 baishuming2020\/centos_nginx<br>WARNING: IPv4 forwarding is disabled. Networking will not work.<br>67f2c276123c993cd66b9d7a99ba22402331a13f9ea8817e57324a934896b805<br>\u200b<br>\u89e3\u51b3\u65b9\u6848<br>1\u3001\u6253\u5f00\u8f6c\u53d1<br>[root@wing ~]# echo \"net.ipv4.ip_forward=1\" &gt;&gt;  \/usr\/lib\/sysctl.d\/00-system.conf<br>\u200b<br>2\u3001\u91cd\u542f\u7f51\u7edc<br>[root@wing ~]# systemctl restart network<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc-19\">\u4e09\u3001\u4e0d\u540c\u4e3b\u673a\u95f4\u7684\u5bb9\u5668\u901a\u4fe1<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-20\">3.1\u3001 macvlan<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728 Docker \u4e2d\uff0cmacvlan \u662f\u4f17\u591a Docker \u7f51\u7edc\u6a21\u578b\u4e2d\u7684\u4e00\u79cd\uff0c\u5e76\u4e14\u662f\u4e00\u79cd\u8de8\u4e3b\u673a\u7684\u7f51\u7edc\u6a21\u578b\uff0c\u4f5c\u4e3a\u4e00\u79cd\u9a71\u52a8\u542f\u7528\uff0cDocker macvlan \u53ea\u652f\u6301 bridge \u6a21\u5f0f<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#macvlan \u9700\u8981\u4e00\u5757\u72ec\u7acb\u7684\u7f51\u5361\u6765\u8fdb\u884c\u4f7f\u7528\uff0c\u6240\u4ee5\u6211\u4eec\u9700\u8981\u65b0\u6dfb\u52a0\u4e00\u5757\u7f51\u5361<br>\u200b<br>docker network create -d macvlan --subnet=172.16.10.0\/24 --gateway=172.16.10.1  -o parent=ens224  mtacvlan-1<br>\u200b<br>-o parent=\u7f51\u5361\u540d\u79f0  \u6307\u5b9a\u7528\u6765\u7ed9 macvlan \u7f51\u7edc\u4f7f\u7528\u7684\u7269\u7406\u7f51\u5361<br>\u200b<br>\u6ce8\u610f\uff0c\u8981\u5728\u6240\u6709\u9700\u8981\u8fd0\u884c macvlan \u7684\u4e3b\u673a\u4e0a\u6267\u884c\u8fd9\u6761\u547d\u4ee4\uff0c\u4f46\u662f\u8981\u8bb0\u5f97\u66f4\u6539\u7f51\u5173\u7684\u5730\u5740\uff0c\u907f\u514d\u9020\u6210IP\u51b2\u7a81<br>\u200b<br>docker run -itd --network macvlan-1 centos \/bin\/bash<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-21\">3.2\u3001 overlay<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728 Docker \u4e2d\uff0coverlay \u662f\u4f17\u591a Docker \u7f51\u7edc\u6a21\u578b\u4e2d\u7684\u4e00\u79cd\uff0c\u5e76\u4e14\u662f\u4e00\u79cd\u8de8\u4e3b\u673a\u7684\u5168\u5c40\u7f51\u7edc\u6a21\u578b\uff0c\u6709\u4e00\u4e2a\u6570\u636e\u5e93\u4e13\u95e8\u7684\u6765\u5b58\u50a8\u7f51\u7edc\u5206\u914d\u4fe1\u606f\uff0c\u907f\u514d IP \u51b2\u7a81\uff0c\u540c\u65f6\u5185\u90e8\u8fd8\u6709\u4e00\u4e2a\u5c0f\u578b\u7684 DNS \u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u901a\u8fc7\u4e3b\u673a\u540d\u8fdb\u884c\u8bbf\u95ee<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">consul \u670d\u52a1\u7aef\uff1a<br>docker run -itd -h consul --name consul --restart=always -p 8500:8500 progrium\/consul -server -bootstrap<br>\u200b<br>-h              \u4e3b\u673a\u540d<br>\u2013name           \u5bb9\u5668\u540d<br>\u2013restart=always \u91cd\u542f\u7b56\u7565<br>progrium\/consul \u955c\u50cf\u540d\u79f0<br>-server         \u4ee5\u670d\u52a1\u8282\u70b9\u542f\u52a8<br>-bootstrap      \u9884\u671f\u7684\u542f\u52a8\u8282\u70b9\u6570\uff1a\u81ea\u4e3e<br>\u200b<br>\u5728\u6d4f\u89c8\u5668\u5185\u8f93\u5165 IP\u5730\u5740+\u7aef\u53e3\u53f7 \u53ef\u4ee5\u770b\u5230 web \u9875\u9762<br>\u200b<br>\u5728\u6240\u6709\u4e3b\u673a\u4e0a\u7f16\u8f91 daemon.json \u6587\u4ef6\uff1a<br>{<br>\"hosts\": [\"tcp:\/\/0.0.0.0:2375\",\"unix:\/\/\/var\/run\/docker.sock\"]\uff0c \u76d1\u542c\u76f8\u5173\u7aef\u53e3<br>\"cluster-store\":\"consul:\/\/192.168.1.150:8500\",       &nbsp; \u96c6\u7fa4\u7684\u4e3b\u673a\u5730\u5740<br>\"cluster-advertise\":\"192.168.1.150:2375\u201d        \u5ba3\u544a\u81ea\u5df1\u7684\u5730\u5740 <br>}<br>\u200b<br>\u91cd\u542f docker \u670d\u52a1<br>\u200b<br>\u521b\u5efa overlay \u7f51\u7edc\uff08\u5168\u5c40\u7f51\u7edc\uff09\uff1a\u4e00\u53f0\u4e3b\u673a\u4e0a\u521b\u5efa\u81ea\u52a8\u540c\u6b65<br>\u200b<br>    docker network create -d overlay overlay-1<br>\u200b<br>\u542f\u52a8\u5bb9\u5668\u6d4b\u8bd5\uff1a<br>\u200b<br>    docker run -it --name docker-1 --network=overlay-1 centos \/bin\/bash<br>    <br>    docker run -it --name docker-2 --network=overlay-1 centos \/bin\/bash<br>    <br>\u9a8c\u8bc1\uff1aping docker-1<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"toc-22\">\u5e38\u89c1\u6545\u969c<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u53d1\u73b0\u5404\u5bb9\u5668\u5185\u5206\u914d\u7684ip\u4e4b\u95f4\u76f8\u4e92ping\u4e0d\u901a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\u539f\u56e0\uff1a\u53ef\u80fd\u7531\u4e8e\u9632\u706b\u5899\u95ee\u9898\u5f15\u8d77\u7684,\u9ed8\u8ba4forward\u94fe\u662fdrop\u72b6\u6001\uff0c\u9700\u8981\u6253\u5f00\u624d\u53ef\u4ee5<br>\u200b<br>\u200b<br>\u89e3\u51b3\u65b9\u6848:<br>\u6267\u884c\u4e0b\u9762\u64cd\u4f5c\uff0c\u4fdd\u8bc1INPUT  FORWARD\u94fe\u90fd\u662fACCEPT\u72b6\u6001<br>\u6e05\u9664\u5176\u4ed6\u89c4\u5219<br>[root@wing_node1 ~]# iptables -P INPUT ACCEPT<br>[root@wing_node1 ~]# iptables -P FORWARD ACCEPT<br>[root@wing_node1 ~]# iptables -F<br>[root@wing_node1 ~]# iptables -L -n<br>\u200b<br>\u200b<br>[root@wing_node2 ~]# iptables -P INPUT ACCEPT<br>[root@wing_node2 ~]# iptables -P FORWARD ACCEPT<br>[root@wing_node2 ~]# iptables -F<br>[root@wing_node2 ~]# iptables -L -n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001Docker \u7f51\u7edc docker\u7f51\u7edc\u4e3b\u8981\u662f\u89e3\u51b3\u5bb9\u5668\u8054\u7f51\u95ee\u9898\uff0c\u4e5f\u662f\u6211\u4eec\u4f7f\u7528\u5bb9\u5668\u4e2d\u6700\u91cd\u8981\u7684\u4e00\u4e2a\u73af\u8282\uff0c\u5982\u679c\u5bb9\u5668\u6ca1 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[],"class_list":["post-340","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/www.xxiaoteng.cn\/index.php?rest_route=\/wp\/v2\/posts\/340","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xxiaoteng.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xxiaoteng.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xxiaoteng.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xxiaoteng.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=340"}],"version-history":[{"count":1,"href":"https:\/\/www.xxiaoteng.cn\/index.php?rest_route=\/wp\/v2\/posts\/340\/revisions"}],"predecessor-version":[{"id":341,"href":"https:\/\/www.xxiaoteng.cn\/index.php?rest_route=\/wp\/v2\/posts\/340\/revisions\/341"}],"wp:attachment":[{"href":"https:\/\/www.xxiaoteng.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=340"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xxiaoteng.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=340"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xxiaoteng.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=340"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}