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

人气:275 发布:2022-09-21 标签: networking docker lxc

问题描述

我一直在尝试将我的五个公共ip中的一个分配给我的docker容器。似乎这是可能的,因为码头的性质及其用途。我发现这个网站,我认为解释了我想做什么,但是从Docker离开LXC起就不再工作了。

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

我尝试使用我的容器正在使用的ip进行静态NAT连接,但没有起作用。 docker IP不显示在我的路由器页面,只有主机ip。

我的问题是:

是否可以为docker容器分配一个静态的public ip,如果是这样呢?

是否可以在我的路由器配置页面中出现docker IP,如果是这样?

谢谢。

解决方案

可能的解决方案,但我现在无法测试。请让我知道这是不正确的。

使用macvlan进行虚拟网络接口:

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

命令:

ip link add dev macvlan0 link eth0 type macvlan#macvlan0是v-card(lol)的名称

将容器连接到具有管道功能的虚拟网络接口:

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

命令:

pipework macvlan0 $($ containerid)dhcp

I have been trying to assign one of my five public ip's to my docker container. It seems like this should be possible because of the nature of docker and its uses. I found this website that I think explains what I want to do but it no longer works since Docker went away from LXC:

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. The docker IP does not show up in my routers page, only the host computers ip.

My questions are:

Is it possible to assign a static public ip to a docker container, and if so how?

and

Is it possible to make a docker IP appear in my router config page, and if so how?

Thanks.

解决方案

Possible Solution but I can't test it right now. Please let me know if this is incorrect.

Make virtual network interface with macvlan:

See 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)

Connect container to virtual network interface with pipework:

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

commands:

pipework macvlan0 $($containerid) dhcp

513