2016-02-05 9 views
5

我希望在VM主機之外的獨立特定IP地址(192.168.0.222,192.168.0.227)之外提供兩個容器,無需端口映射。這意味着我希望通過使用IP直接訪問容器上的任何端口。我已經在虛擬機主機之外的網絡中運行了192.168.0.1-192.168.0.221範圍內的機器。如何將特定IP分配給容器並使其可在VM主機之外訪問?

Docker 1.10.0現在可以嗎?如果是這樣,怎麼樣?

我使用boot2docker/VirtualBox驅動程序在OS X 10.11上使用docker version 1.10.0, build 590d5108docker-machine version 0.6.0, build e27fb87


我一直在試圖弄清楚這一點了一會兒,沒有運氣,我已經閱讀下列問題及解答:

回答

3

根據Jessie Frazelle,這肩膀現在有可能。
請參閱「IPs for all the Things

這太酷我幾乎無法承受。

在Docker 1.10中,令人敬畏的libnetwork團隊添加了爲容器指定特定IP的功能。如果你想看到拉請求在這裏:docker/docker#19001

# create a new bridge network with your subnet and gateway for your ip block 
$ docker network create --subnet 203.0.113.0/24 --gateway 203.0.113.254 iptastic 

# run a nginx container with a specific ip in that block 
$ docker run --rm -it --net iptastic --ip 203.0.113.2 nginx 

# curl the ip from any other place (assuming this is a public ip block duh) 
$ curl 203.0.113.2 

# BOOM golden 

這確實說明了new docker run --ip option,你現在在docker network connect看到。

如果指定,當重新啓動停止的容器時,將重新應用容器的IP地址。如果IP地址不再可用,則容器無法啓動。

確保IP地址可用的一種方法是在創建網絡時指定--ip-range,並從該範圍之外選擇靜態IP地址。這確保了當該容器不在網絡上時,IP地址不會被提供給另一個容器。

$ docker network create --subnet 172.20.0.0/16 --ip-range 172.20.240.0/20 multi-host-network 

$ docker network connect --ip 172.20.128.2 multi-host-network container2 

的 「使人人皆可訪問」 部分將涉及,像往常一樣,port forwarding

相關問題