Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 816
Lakshmikanth B Avatar asked Dec 04 '22 20:12

Lakshmikanth B


2 Answers

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
like image 120
Vipul Vaibhaw Avatar answered Jan 22 '23 19:01

Vipul Vaibhaw


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

-p 192.168.150.3:6379:6379

like image 45
Harshit Chawla Avatar answered Jan 22 '23 19:01

Harshit Chawla