Docker container Network connection between different host

loser5566

I installed docker on two hosts (Virtual Machines). I'd like to make the containers on different host to be able to connect each other.

Here's VM1's and VM2's ifconfig output:

VM1

bridge0 : inet addr:172.17.52.1  Bcast:172.17.52.255  Mask:255.255.255.0
docker0 : inet addr:172.17.42.1  Bcast:0.0.0.0  Mask:255.255.0.0
eth0 : inet addr:192.168.122.129  Bcast:192.168.122.255  Mask:255.255.255.0

VM2

bridge0 : inet addr:172.17.53.1  Bcast:172.17.53.255  Mask:255.255.255.0
docker0 : inet addr:172.17.42.1  Bcast:0.0.0.0  Mask:255.255.0.0
eth0 : inet addr:192.168.122.77  Bcast:192.168.122.255  Mask:255.255.255.0

bridge is used for the container. I have made some network configurations:

iptables -t nat -A POSTROUTING -s 172.17.52.0/24 ! -d 172.17.0.0/16 -j MASQUERADE (on VM1)
iptables -t nat -A POSTROUTING -s 172.17.53.0/24 ! -d 172.17.0.0/16 -j MASQUERADE (on VM2)
route add -net 172.17.52.0 netmask 255.255.255.0 gw 192.168.122.129 (on VM2)
route add -net 172.17.53.0 netmask 255.255.255.0 gw 192.168.122.77 (on VM1)

I get no output when a container pings another container

(172.17.52.X ping 172.17.53.X)

VM1 can ping VM2 successfully. The container on VM1 can also ping VM2 successfully, but I get no output when the container on VM1 pings the container on VM2.

errordeveloper

One very easy way to achieve this would be by using Weave.

You can install it with:

sudo wget -O /usr/local/bin/weave \
  https://github.com/zettio/weave/releases/download/latest_release/weave
sudo chmod a+x /usr/local/bin/weave

VM1

sudo weave launch
C=$(sudo weave run 10.2.1.1/24 -t -i busybox)

VM2

sudo weave launch 192.168.122.129
C=$(sudo weave run 10.2.1.2/24 -t -i busybox)
docker exec $C ping -c 3 10.2.1.1/24

You have just create a virtual network with containers. The beauty is that these VMs can be anywhere, as long as at least one of them has public IP with port 6783 open.

You can even enable NaCL crypto by running weave launch -password "<MySecret>" or (exporting WEAVE_PASSWORD="<MySecret>" prior to weave launch).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Network connection between 2 Docker Container (JBOSS/DATABASE)

From Dev

Docker - Run Apache on host and container for different websites

From Dev

use docker container on host network without sharing host's ip

From Dev

use docker container on host network without sharing host's ip

From Dev

What is the difference between Docker Host and Container

From Dev

Communication between Windows Host and Linux Docker Container

From Dev

How to reach a docker container from a device that is in the same network as the docker host?

From Dev

Connection issue between Docker container and Other machine

From Dev

SSH into a docker container from another container on a different host

From Dev

Outbound telnet connection from Docker container refused but works fine on host

From Java

How to connect to a docker container from outside the host (same network) [Windows]

From Dev

How to put docker container for database on a different host in production?

From Dev

How to put docker container for database on a different host in production?

From Java

What is the relationship between the docker host OS and the container base image OS?

From Java

Networking between KVM VM and docker container on same host

From Dev

Share files between host system and docker container using specific UID

From Dev

Inter-process communication between docker container and its host

From Dev

how to share folder between host os and docker container

From Dev

Link docker container with host

From Dev

Add docker container to network under two different names

From Dev

Add docker container to network under two different names

From Dev

How do I connect a Docker container running in boot2docker to a network service running on another host?

From Dev

Jenkins: connection between docker container with jenkins master and docker container with jenkins slave

From Dev

Connection refused on docker container

From Dev

Docker container not exposed on network

From Dev

Docker container ssh error: ssh_exchange_identification: Connection closed by remote host

From Dev

Accessing other machines on a vagrant/virtual box host only network from within a docker container

From Dev

Is it possible in some way to use POSIX semaphores between Docker containers or between a container and the host?

From Dev

Is it possible in some way to use POSIX semaphores between Docker containers or between a container and the host?

Related Related

  1. 1

    Network connection between 2 Docker Container (JBOSS/DATABASE)

  2. 2

    Docker - Run Apache on host and container for different websites

  3. 3

    use docker container on host network without sharing host's ip

  4. 4

    use docker container on host network without sharing host's ip

  5. 5

    What is the difference between Docker Host and Container

  6. 6

    Communication between Windows Host and Linux Docker Container

  7. 7

    How to reach a docker container from a device that is in the same network as the docker host?

  8. 8

    Connection issue between Docker container and Other machine

  9. 9

    SSH into a docker container from another container on a different host

  10. 10

    Outbound telnet connection from Docker container refused but works fine on host

  11. 11

    How to connect to a docker container from outside the host (same network) [Windows]

  12. 12

    How to put docker container for database on a different host in production?

  13. 13

    How to put docker container for database on a different host in production?

  14. 14

    What is the relationship between the docker host OS and the container base image OS?

  15. 15

    Networking between KVM VM and docker container on same host

  16. 16

    Share files between host system and docker container using specific UID

  17. 17

    Inter-process communication between docker container and its host

  18. 18

    how to share folder between host os and docker container

  19. 19

    Link docker container with host

  20. 20

    Add docker container to network under two different names

  21. 21

    Add docker container to network under two different names

  22. 22

    How do I connect a Docker container running in boot2docker to a network service running on another host?

  23. 23

    Jenkins: connection between docker container with jenkins master and docker container with jenkins slave

  24. 24

    Connection refused on docker container

  25. 25

    Docker container not exposed on network

  26. 26

    Docker container ssh error: ssh_exchange_identification: Connection closed by remote host

  27. 27

    Accessing other machines on a vagrant/virtual box host only network from within a docker container

  28. 28

    Is it possible in some way to use POSIX semaphores between Docker containers or between a container and the host?

  29. 29

    Is it possible in some way to use POSIX semaphores between Docker containers or between a container and the host?

HotTag

Archive