Alireza Amiri
Alireza Amiri

Reputation: 511

Docker - connection between containers in different hosts within the same overlay network

In my scenario I use "consul" as the key-value store backend, and two more VMs with docker installed on them. The command I am running the docker daemon on these two VMs is:

sudo docker daemon -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock \
--cluster-store consul://{CONSUL_IP}:8500  --cluster-advertise eth0:2376

Also the command for running the consul is :

sudo docker daemon -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock

After this, I try to create a network using:

sudo docker network create -d overlay --subnet=192.168.3.0/24 my-overlay

And in each of VMs I run a busybox container:

sudo docker run -itd --name containerX --net my-overlay busybox

Where X is A for one of them and B for another.

here is "docker info" from the first VM:

$ sudo docker info
Containers: 4
 Running: 2
 Paused: 0
 Stopped: 2
Images: 3
Server Version: 1.12.3
Storage Driver: aufs
 Root Dir: /var/lib/docker/aufs
 Backing Filesystem: extfs
 Dirs: 17
 Dirperm1 Supported: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: overlay bridge host null
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Security Options: apparmor
Kernel Version: 3.13.0-76-generic
Operating System: Ubuntu 14.04.3 LTS
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 1.955 GiB
Name: cs-webserving-4
ID: ESSZ:WBCV:W6NU:ODJ6:3ZIW:QHMH:TEXP:M66M:NYF5:MNWB:H4M7:Z3L6
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
WARNING: No swap limit support
Cluster Store: consul://10.254.1.92:8500
Cluster Advertise: 10.254.1.123:2376
Insecure Registries:
 127.0.0.0/8

And here is the other VM:

$ sudo docker info
Containers: 4
 Running: 2
 Paused: 0
 Stopped: 2
Images: 3
Server Version: 1.12.3
Storage Driver: aufs
 Root Dir: /var/lib/docker/aufs
 Backing Filesystem: extfs
 Dirs: 17
 Dirperm1 Supported: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: overlay host bridge null
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Security Options: apparmor
Kernel Version: 3.13.0-76-generic
Operating System: Ubuntu 14.04.3 LTS
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 1.955 GiB
Name: cs-webserving-3
ID: BTAL:L3LE:BHSX:DQRD:HTC4:KXJE:T772:47TU:4KJZ:NIY4:7WTY:Q6TO
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
WARNING: No swap limit support
Cluster Store: consul://10.254.1.92:8500
Cluster Advertise: 10.254.1.122:2376
Insecure Registries:
 127.0.0.0/8

Problem When I try to ping containerB from containerA, I get no answer:

sudo docker exec containerB ping -w 5 192.168.3.5
PING 192.168.3.5 (192.168.3.5): 56 data bytes

--- 192.168.3.5 ping statistics ---
5 packets transmitted, 0 packets received, 100% packet loss

Where 192.168.3.5 is the IP of containerA in overlay network. **Note: ** I also tried the name "containerA" instead of the IP, it didn't work neither.

What is the problem in my scenario? any hint or solutions would be appreciated.

Upvotes: 1

Views: 149

Answers (2)

Dockstar
Dockstar

Reputation: 1028

What version of Docker are you using? Currently, traditional containers are not allowed to connect to overlay networks, only services are. That will be fixed in version 1.13 with the --attachable keyword for overlay network creation.

What may make more sense is to create two services on the same overlay network. Then they'll be able to refer to each other directly by service name.

Upvotes: 0

YYY
YYY

Reputation: 6341

Try linking containers.

Ex:

$ docker run -ti --name containerA --link containerB:containerB_alias  ubuntu bash 

You can ping: [root@cad0fef8c778]$ ping containerB_alias

Upvotes: 1

Related Questions