简体   繁体   English

是否可以将静态公共IP分配给Docker容器?

[英]Is it possible to assign a static public ip to a Docker Container?

I have been trying to assign one of my five public ip's to my docker container. 我一直在尝试将五个公共IP之一分配给我的docker容器。 It seems like this should be possible because of the nature of docker and its uses. 由于docker的性质及其用途,似乎这应该是可能的。 I found this website that I think explains what I want to do but it no longer works since Docker went away from LXC: 我找到了我认为可以解释我要做什么的网站,但是自从Docker离开LXC以来,它不再起作用:

http://programster.blogspot.com/2014/06/docker-run-multiple-docker-websites-on.html http://programster.blogspot.com/2014/06/docker-run-multiple-docker-websites-on.html

I have tried making a static NAT connection with the ip that my container was using but that didn't work. 我曾尝试与我的容器使用的IP建立静态NAT连接,但无法正常工作。 The docker IP does not show up in my routers page, only the host computers ip. docker IP没有显示在我的路由器页面上,只有主机IP才显示。

My questions are: 我的问题是:

Is it possible to assign a static public ip to a docker container, and if so how? 是否可以将静态公共IP分配给Docker容器,如果可以,如何做?

and

Is it possible to make a docker IP appear in my router config page, and if so how? 是否可以在我的路由器配置页面上显示一个docker IP,如果可以,怎么办?

Thanks. 谢谢。

Docker 1.10 will allow you to specify a static IP-address for a container for each network it's connected to. Docker 1.10允许您为容器所连接的每个网络指定一个静态IP地址。

(Note that, for backward compatibility, this feature is only supported for custom networks, and only if a subnet is specified) (请注意,为了向后兼容,此功能仅支持自定义网络,并且仅在指定了子网的情况下才支持)

For example; 例如;

docker network create -d bridge --subnet 172.25.0.0/16 mynet

docker run -d --net=mynet --ip=172.25.3.3 nginx

For more information see the documentation pull request 有关更多信息,请参见文档请求请求

The only way I know of to have a docker container use a static ip is using pipework . 我知道让docker容器使用静态ip的唯一方法是使用管道

Assuming you mean acquiring a DHCP lease and showing up on your router page -- Nothing comes to mind with docker. 假设您的意思是获取DHCP租约并显示在路由器页面上-Docker没什么用。 I don't think that is "the docker way". 我不认为这是“码头工人的方式”。 It's pretty simple with nspawn if you are using a systemd based distro, FWIW. 如果您使用的是基于Systemd的发行版FWIW,则使用nspawn非常简单。

Possible Solution but I can't test it right now. 可能的解决方案,但我现在无法测试。 Please let me know if this is incorrect. 如果这不正确,请通知我。

Make virtual network interface with macvlan: 使用macvlan创建虚拟网络接口:

See https://superuser.com/questions/175475/ip-address-alias-assigned-by-dhcp 参见https://superuser.com/questions/175475/ip-address-alias-assigned-by-dhcp

commands: 命令:

ip link add dev macvlan0 link eth0 type macvlan #macvlan0 being the name of the v-card (lol) ip link add dev macvlan0 link eth0类型macvlan#macvlan0是v卡的名称(lol)

Connect container to virtual network interface with pipework: 使用管道将容器连接到虚拟网络接口:

see https://github.com/jpetazzo/pipework/#connect-a-container-to-a-local-physical-interface 参见https://github.com/jpetazzo/pipework/#connect-a-container-to-a-local-physical-interface

commands: 命令:

pipework macvlan0 $($containerid) dhcp 管道系统macvlan0 $ {$ containerid)dhcp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM