is it possible to change the ip of docker0 or provide a static IP to docker containers, because by default docker containers have the ip range of 172.17.0.2/16 but my network is 192.168.X.X/24 in this situation on the server container is running there all the containers is able to communicate within servers but from other server this failed to connect.
-
Possible duplicate of [Is it possible to assign a static public ip to a Docker Container?](http://stackoverflow.com/questions/27516284/is-it-possible-to-assign-a-static-public-ip-to-a-docker-container) – roottraveller Dec 16 '15 at 04:50
-
in my scenario m running docker on two hosts and create a cluster, but due to IP problem my 2nd host container is unable to communicate with cluster nodes and failed to build cluster. – anand Dec 16 '15 at 05:12
4 Answers
How do you set up your cluster? Do you use Swarm? If so, you need to use a k/v storage backend to enable communication between two containers hosted on different hosts. Is this what you aim to do, or do you want the host to communicate with the container on the other host? Anyway, the solution is similar.
I re-writing a tuto for Docker Swarm to pull request it into their Swarm doc, you may want to take a look: https://www.auzias.net/en/docker-network-multihost/
Have a nice day!

- 3,638
- 14
- 36
-
i haven't use swarm, actually m running two nodes on one host which are able to communicate with each other, and two nodes are running on another host, but problem is 1st host nodes are not able to communicate with 2nd host nodes and cluster is failed. – anand Dec 20 '15 at 05:18
-
What do you mean "the cluster is failed"? Mulithost networking is not that straitforward. – Auzias Dec 22 '15 at 13:53
-
*previous message was [enter] typo* You can find some doc here : - https://github.com/docker/docker/issues/8951 - http://blog.docker.com/2015/11/docker-multi-host-networking-ga/ - https://docs.docker.com/engine/userguide/networking/get-started-overlay/ – Auzias Dec 22 '15 at 14:03
problem can be fix by using --network=host
this will allow your container to use the host machine network. for direct accessing your container you can change the ssh port of the container and access your container with the specific port number.

- 11
- 6
I answered a similar question here https://stackoverflow.com/a/35359185/4094678
The difference in your case would be to create a netowrk with subnet 192.168.X.X/24 and then assign desired ip addr to container with --ip

- 1
- 1

- 9,691
- 5
- 31
- 42
-
Can u be more specific,means how to assign IP of the same network of host machine, as I told container and hosts IP is different – anand Feb 17 '16 at 17:54
-
1With `--ip` you can set the ip address to anything you want. Before that you need to create your own subnet. (just check the link). Now, if you want that your host and the containers to be in the same network you need to use `--net=host` – cantSleepNow Feb 17 '16 at 20:24
Here we can't able to change docker0 Ip address, but we have option to create multiple networks.
Solution 1:
can be by using start container with host network --network=host
Solution2:
we can also start the container by exposing the cluster required port and from another node we can communicate it.
-p hostport:serviceport
Or, Solution3:
We can deploy cluster over docker swarm.

- 741
- 5
- 11