How to change the IP address of a docker after creating it?

天涯浪子 提交于 2020-01-24 13:12:32

问题


I have a docker linked to a bridge with IP address 192.168.150.1/24. Once I create the docker instance from a docker image it gets an IP address, 192.168.150.2, but according to my requirement, this IP address, 192.168.150.2, must be reserved since I want to use it for some other thing.

Now, I want to change the IP address of this docker instance as 192.168.150.3. Is it possible to do? if so how? Please, help.


回答1:


You will have to first detach the container from the custom network and the connect it back by providing the ip.

You can follow the following steps :

  1. docker network disconnect [OPTIONS] NETWORK CONTAINER
  2. docker network connect --ip 192.168.150.3 NETWORK CONTAINER



回答2:


You can specify a particular IP address when you define the port mapping, for example

-p 192.168.150.3:6379:6379




回答3:


here is another option, try to use -b bridge option to use a certain ip range, like for instance -b br0=192.168.150.3/24 here is more complete example configure docker bridge network



来源:https://stackoverflow.com/questions/48088832/how-to-change-the-ip-address-of-a-docker-after-creating-it

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