Lakshmikanth B
Lakshmikanth B

Reputation: 105

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

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.

Upvotes: 5

Views: 15139

Answers (3)

Harshit Chawla
Harshit Chawla

Reputation: 113

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

-p 192.168.150.3:6379:6379

Upvotes: 2

Fendi jatmiko
Fendi jatmiko

Reputation: 2895

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

Upvotes: 0

Vipul Vaibhaw
Vipul Vaibhaw

Reputation: 433

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

Upvotes: 19

Related Questions