docker容器內部無法串連宿主機所在區域網路

來源:互聯網
上載者:User
關鍵字 docker php centos
  1. 使用centos鏡像建立容器,在容器內部署php項目,由於要向宿主機所在區域網路的另一台伺服器請求介面服務,發起的http請求始終串連不上,但可以串連國際互連網。

2.
宿主機IP:172.20.20.152,
請求介面的目標伺服器IP:172.17.3.97

建立Docker容器的命令:
docker run -p 80:80 --name=mycns -it eeb3a076a0be /bin/bash

進入容器後,執行命令:
ping 172.17.3.97
返回結果是:
From 172.17.0.3 icmp_seq=1 Destination Host Unreachable
From 172.17.0.3 icmp_seq=2 Destination Host Unreachable
From 172.17.0.3 icmp_seq=3 Destination Host Unreachable
From 172.17.0.3 icmp_seq=4 Destination Host Unreachable
From 172.17.0.3 icmp_seq=5 Destination Host Unreachable
From 172.17.0.3 icmp_seq=6 Destination Host Unreachable
From 172.17.0.3 icmp_seq=8 Destination Host Unreachable
From 172.17.0.3 icmp_seq=9 Destination Host Unreachable

安裝docker版本資訊:
docker version
返回:
Client version: 1.7.1
Client API version: 1.19
Go version (client): go1.4.2
Git commit (client): 786b29d/1.7.1
OS/Arch (client): linux/amd64
Server version: 1.7.1
Server API version: 1.19
Go version (server): go1.4.2
Git commit (server): 786b29d/1.7.1
OS/Arch (server): linux/amd64

3.
宿主機執行ifconfig命令,返回:
docker0 Link encap:Ethernet HWaddr EE:25:C5:DA:10:47

      inet addr:172.17.42.1  Bcast:0.0.0.0  Mask:255.255.0.0      inet6 addr: fe80::200:ff:fe00:0/64 Scope:Link      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1      RX packets:64400 errors:0 dropped:0 overruns:0 frame:0      TX packets:69800 errors:0 dropped:0 overruns:0 carrier:0      collisions:0 txqueuelen:0       RX bytes:3945235 (3.7 MiB)  TX bytes:105962604 (101.0 MiB)

eth0 Link encap:Ethernet HWaddr F2:3D:F0:2B:43:31

      inet addr:172.20.20.152  Bcast:172.20.255.255  Mask:255.255.0.0      inet6 addr: fe80::f03d:f0ff:fe2b:4331/64 Scope:Link      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1      RX packets:29702118 errors:0 dropped:0 overruns:0 frame:0      TX packets:583992 errors:0 dropped:0 overruns:0 carrier:0      collisions:0 txqueuelen:1000       RX bytes:2997801386 (2.7 GiB)  TX bytes:73288231 (69.8 MiB)

lo Link encap:Local Loopback

      inet addr:127.0.0.1  Mask:255.0.0.0      inet6 addr: ::1/128 Scope:Host      UP LOOPBACK RUNNING  MTU:65536  Metric:1      RX packets:7059 errors:0 dropped:0 overruns:0 frame:0      TX packets:7059 errors:0 dropped:0 overruns:0 carrier:0      collisions:0 txqueuelen:0       RX bytes:4819120 (4.5 MiB)  TX bytes:4819120 (4.5 MiB)

veth50f5616 Link encap:Ethernet HWaddr EE:25:C5:DA:10:47

      inet6 addr: fe80::ec25:c5ff:feda:1047/64 Scope:Link      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1      RX packets:17 errors:0 dropped:0 overruns:0 frame:0      TX packets:6 errors:0 dropped:0 overruns:0 carrier:0      collisions:0 txqueuelen:0       RX bytes:1014 (1014.0 b)  TX bytes:468 (468.0 b)

4.
宿主機本可以正常串連172.17.3.97這台機器,但docker服務啟動後,無法正常串連。

來一位大神幫看看呵呵

回複內容:

  1. 使用centos鏡像建立容器,在容器內部署php項目,由於要向宿主機所在區域網路的另一台伺服器請求介面服務,發起的http請求始終串連不上,但可以串連國際互連網。

2.
宿主機IP:172.20.20.152,
請求介面的目標伺服器IP:172.17.3.97

建立Docker容器的命令:
docker run -p 80:80 --name=mycns -it eeb3a076a0be /bin/bash

進入容器後,執行命令:
ping 172.17.3.97
返回結果是:
From 172.17.0.3 icmp_seq=1 Destination Host Unreachable
From 172.17.0.3 icmp_seq=2 Destination Host Unreachable
From 172.17.0.3 icmp_seq=3 Destination Host Unreachable
From 172.17.0.3 icmp_seq=4 Destination Host Unreachable
From 172.17.0.3 icmp_seq=5 Destination Host Unreachable
From 172.17.0.3 icmp_seq=6 Destination Host Unreachable
From 172.17.0.3 icmp_seq=8 Destination Host Unreachable
From 172.17.0.3 icmp_seq=9 Destination Host Unreachable

安裝docker版本資訊:
docker version
返回:
Client version: 1.7.1
Client API version: 1.19
Go version (client): go1.4.2
Git commit (client): 786b29d/1.7.1
OS/Arch (client): linux/amd64
Server version: 1.7.1
Server API version: 1.19
Go version (server): go1.4.2
Git commit (server): 786b29d/1.7.1
OS/Arch (server): linux/amd64

3.
宿主機執行ifconfig命令,返回:
docker0 Link encap:Ethernet HWaddr EE:25:C5:DA:10:47

      inet addr:172.17.42.1  Bcast:0.0.0.0  Mask:255.255.0.0      inet6 addr: fe80::200:ff:fe00:0/64 Scope:Link      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1      RX packets:64400 errors:0 dropped:0 overruns:0 frame:0      TX packets:69800 errors:0 dropped:0 overruns:0 carrier:0      collisions:0 txqueuelen:0       RX bytes:3945235 (3.7 MiB)  TX bytes:105962604 (101.0 MiB)

eth0 Link encap:Ethernet HWaddr F2:3D:F0:2B:43:31

      inet addr:172.20.20.152  Bcast:172.20.255.255  Mask:255.255.0.0      inet6 addr: fe80::f03d:f0ff:fe2b:4331/64 Scope:Link      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1      RX packets:29702118 errors:0 dropped:0 overruns:0 frame:0      TX packets:583992 errors:0 dropped:0 overruns:0 carrier:0      collisions:0 txqueuelen:1000       RX bytes:2997801386 (2.7 GiB)  TX bytes:73288231 (69.8 MiB)

lo Link encap:Local Loopback

      inet addr:127.0.0.1  Mask:255.0.0.0      inet6 addr: ::1/128 Scope:Host      UP LOOPBACK RUNNING  MTU:65536  Metric:1      RX packets:7059 errors:0 dropped:0 overruns:0 frame:0      TX packets:7059 errors:0 dropped:0 overruns:0 carrier:0      collisions:0 txqueuelen:0       RX bytes:4819120 (4.5 MiB)  TX bytes:4819120 (4.5 MiB)

veth50f5616 Link encap:Ethernet HWaddr EE:25:C5:DA:10:47

      inet6 addr: fe80::ec25:c5ff:feda:1047/64 Scope:Link      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1      RX packets:17 errors:0 dropped:0 overruns:0 frame:0      TX packets:6 errors:0 dropped:0 overruns:0 carrier:0      collisions:0 txqueuelen:0       RX bytes:1014 (1014.0 b)  TX bytes:468 (468.0 b)

4.
宿主機本可以正常串連172.17.3.97這台機器,但docker服務啟動後,無法正常串連。

來一位大神幫看看呵呵

找到原因了: http://dev.bidlust.com/?p=103

你可以不適用橋接網路,使用僅主機網路,這樣就和主機一模一樣了,docker run添加參數:--net host

應該是防火牆給攔了

  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.