简体   繁体   中英

docker containers static IP to communicate two different hosts

是否可以更改docker0的ip或为docker容器提供静态IP,因为默认情况下docker容器的ip范围为172.17.0.2/16但是我的网络是192.168.XX / 24,在这种情况下服务器容器是在那里运行所有容器都能够在服务器内进行通信,但是从其他服务器无法连接。

How do you set up your cluster? Do you use Swarm? If so, you need to use ak/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!

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.

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.XX/24 and then assign desired ip addr to container with --ip

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM