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

一世执手 提交于 2019-12-02 11:22:21

Docker 1.10 will allow you to specify a static IP-address for a container for each network it's connected to.

(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.

Assuming you mean acquiring a DHCP lease and showing up on your router page -- Nothing comes to mind with 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.

domsl

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!