问题
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 :
docker network disconnect [OPTIONS] NETWORK CONTAINERdocker 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