2017-07-18 78 views
1

嗨,我已經安裝並啓動碼頭集裝箱。當我進入這個容器和做的ifconfig,這是我得到:不能ping我的碼頭集裝箱外的主機

eth0  Link encap:Ethernet HWaddr 02:42:0a:32:00:02 
      inet addr:10.50.0.2 Bcast:0.0.0.0 Mask:255.255.0.0 
      UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 
      RX packets:387 errors:0 dropped:0 overruns:0 frame:0 
      TX packets:18 errors:0 dropped:0 overruns:0 carrier:0 
      collisions:0 txqueuelen:0 
      RX bytes:73801 (73.8 KB) TX bytes:1572 (1.5 KB) 

eth0:1 Link encap:Ethernet HWaddr 02:42:0a:32:00:02 
      inet addr:10.50.1.1 Bcast:10.50.255.255 Mask:255.255.0.0 
      UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 

eth0:2 Link encap:Ethernet HWaddr 02:42:0a:32:00:02 
      inet addr:10.50.1.2 Bcast:10.50.255.255 Mask:255.255.0.0 
      UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 

eth0:3 Link encap:Ethernet HWaddr 02:42:0a:32:00:02 
      inet addr:10.50.1.3 Bcast:10.50.255.255 Mask:255.255.0.0 
      UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 

我可以完美ping通這些地址形成主機(eth0和它的虛擬IPS)

在主機上,這是ifconfig輸出

br-dfd292823ec9 Link encap:Ethernet HWaddr 02:42:1b:2b:32:c3 
      inet addr:10.50.0.1 Bcast:0.0.0.0 Mask:255.255.0.0 
      inet6 addr: fe80::42:1bff:fe2b:32c3/64 Scope:Link 
      UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 
      RX packets:18 errors:0 dropped:0 overruns:0 frame:0 
      TX packets:320 errors:0 dropped:0 overruns:0 carrier:0 
      collisions:0 txqueuelen:0 
      RX bytes:1320 (1.3 KB) TX bytes:65375 (65.3 KB) 

docker0 Link encap:Ethernet HWaddr 02:42:93:9a:5c:ea 
      inet addr:172.17.0.1 Bcast:0.0.0.0 Mask:255.255.0.0 
      inet6 addr: fe80::42:93ff:fe9a:5cea/64 Scope:Link 
      UP BROADCAST MULTICAST MTU:1500 Metric:1 
      RX packets:0 errors:0 dropped:0 overruns:0 frame:0 
      TX packets:23 errors:0 dropped:0 overruns:0 carrier:0 
      collisions:0 txqueuelen:0 
      RX bytes:0 (0.0 B) TX bytes:2967 (2.9 KB) 

eth0  Link encap:Ethernet HWaddr ec:b1:d7:56:9d:88 
      inet addr:10.250.1.49 Bcast:10.250.255.255 Mask:255.255.0.0 
      inet6 addr: fe80::f784:a7df:5e4e:ce2f/64 Scope:Link 
      UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 
      RX packets:270248 errors:0 dropped:0 overruns:0 frame:0 
      TX packets:113084 errors:0 dropped:0 overruns:0 carrier:0 
      collisions:0 txqueuelen:1000 
      RX bytes:208274777 (208.2 MB) TX bytes:67211395 (67.2 MB) 
      Interrupt:20 Memory:f7d00000-f7d20000 

eth1  Link encap:Ethernet HWaddr 68:05:ca:3e:0c:f3 
      inet addr:192.168.108.222 Bcast:192.168.109.255 Mask:255.255.254.0 
      inet6 addr: fe80::8f37:3338:32cf:ba39/64 Scope:Link 
      inet6 addr: 2620:2c:40c0:c00:2d9e:8857:7d24:f4ee/64 Scope:Global 
      UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 
      RX packets:94805 errors:0 dropped:1 overruns:0 frame:0 
      TX packets:19184 errors:0 dropped:0 overruns:0 carrier:0 
      collisions:0 txqueuelen:1000 
      RX bytes:36493713 (36.4 MB) TX bytes:4842334 (4.8 MB) 
      Interrupt:19 Memory:f7cc0000-f7ce0000 

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:11023 errors:0 dropped:0 overruns:0 frame:0 
      TX packets:11023 errors:0 dropped:0 overruns:0 carrier:0 
      collisions:0 txqueuelen:1 
      RX bytes:1730700 (1.7 MB) TX bytes:1730700 (1.7 MB) 

veth06b2b8e Link encap:Ethernet HWaddr 8e:96:03:60:49:5c 
      inet6 addr: fe80::8c96:3ff:fe60:495c/64 Scope:Link 
      UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 
      RX packets:18 errors:0 dropped:0 overruns:0 frame:0 
      TX packets:392 errors:0 dropped:0 overruns:0 carrier:0 
      collisions:0 txqueuelen:0 
      RX bytes:1572 (1.5 KB) TX bytes:74749 (74.7 KB) 

現在我嘗試ping其他機器的容器不會忽略(10.50.0.2,10.50.1.1,...)都在同一個網絡中的主機和路由加入到他們使用主機作爲gw來訪問10.50.0.0/16網絡,但我無法ping泊塢器聯繫iner IP。我使用的是docker 17 ce和ubuntu 16.

+0

爲什麼你需要首先ping它們? – Grimmy

+0

因爲我想ssh容器,不能,我使用端口10050,並通過碼頭運行啓動容器-p 10050:10050,但不能ssh用戶@主機-p 10050,所以我ping。 – user2133558

+0

您正在容器中的端口10050上運行sshd? – Grimmy

回答

1

所以我找到了解決我的問題的方法。事實證明這樣做sudo iptables -L -n我發現下面的

Chain FORWARD (policy DROP) 
target  prot opt source    destination   
DOCKER-USER all -- 0.0.0.0/0   0.0.0.0/0   
DOCKER-ISOLATION all -- 0.0.0.0/0   0.0.0.0/0   
ACCEPT  all -- 0.0.0.0/0   0.0.0.0/0   ctstate RELATED,ESTABLISHED 
DOCKER  all -- 0.0.0.0/0   0.0.0.0/0   
ACCEPT  all -- 0.0.0.0/0   0.0.0.0/0   
ACCEPT  all -- 0.0.0.0/0   0.0.0.0/0   
ACCEPT  all -- 0.0.0.0/0   0.0.0.0/0   ctstate RELATED,ESTABLISHED 
DOCKER  all -- 0.0.0.0/0   0.0.0.0/0   
ACCEPT  all -- 0.0.0.0/0   0.0.0.0/0   
ACCEPT  all -- 0.0.0.0/0   0.0.0.0/0 

於是提出政策設置爲下降,這意味着沒有流量轉發到我的搬運工容器,然後我做了sudo iptables -P FORWARD ACCEPT和解決我的問題。