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 :

  • How to link Docker services across hosts?
  • RHEL7: How to solve “ import read failed(2)”?
  • Electron inside Docker with X11 Forwarding - No Protocol Specified
  • Docker container start error throw input/output error
  • How do I link a container in docker only if it exists when starting the container?
  • Docker. Spring application. set & get environment variable
  • 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.

  • Docker for Azure - no swarm mode?
  • Docker: how to fix “Layer already being pulled by another client. Waiting”
  • /sys on the host is becoming read-only once Docker is started
  • How to ensure to update Docker image on AWS ECS?
  • How to run psutil inside a docker container?
  • Docker run php script
  • 2 Solutions collect form web for “Docker – connection between containers in different hosts within the same overlay network”

    Try linking containers.

    Ex:

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

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

    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.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.