Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bryanhuntesl/fc4dd9847fcf820c81f99addd1a133eb to your computer and use it in GitHub Desktop.
Save bryanhuntesl/fc4dd9847fcf820c81f99addd1a133eb to your computer and use it in GitHub Desktop.

Setup

Create a bridge network which will be shared between containers

⚛︎□▷  docker network create riakcluster_default
e795056ca0f1c2b4c18e9f6614ff1fec5c9b05cfc718fa4c9b9c0b8a54fb0b54

□▷  docker network  ls             
NETWORK ID          NAME                  DRIVER              SCOPE
6112ed304ce5        bridge                bridge              local
7d25cb539e92        host                  host                local
8da2b8c84fe3        none                  null                local
be76ee81992d        riakcluster_default   bridge              local

Create an name the containers - defind both on the same network

Container 'foo' :

⚛︎□▷ docker run --rm --name foo --network riakcluster_default -ti ubuntu /bin/bash
root@e0364b941c56:/# ping bar

Container 'bar' :

⚛︎□▷ docker run --rm --name bar --network riakcluster_default -ti ubuntu /bin/bash
root@0a5f0df8676c:/# apt-get update &> /dev/null & apt-get install -y iputils-ping &> /dev/null

ICMP communication between hosts.

Ping 'foo' container from 'bar' container.

root@0a5f0df8676c:/# ping foo
PING foo (172.18.0.2) 56(84) bytes of data.
64 bytes from foo.riakcluster_default (172.18.0.2): icmp_seq=1 ttl=64 time=1.21 ms
^C
--- foo ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 1.210/1.210/1.210/0.000 ms
root@0a5f0df8676c:/#

Demonstrate arbitrary port communication:

Run on both containers :

apt-get update -y &> /dev/null 
apt-get install -y netcat &> /dev/null

Container 'foo' - start a listening TCP server :

root@e0364b941c56:/# netcat -l -p8080

Container 'bar' :

Send a couple of messages over TCP to the netcat daemon listening on container 'foo':

root@0a5f0df8676c:/# netcat foo 8080
test
test from bar

Container 'foo' :

Observe the messages received by the listening netcat session..

root@e0364b941c56:/# netcat -l -p8080
test
test from bar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment