#+title: Docker GNATSD Cluster example #+property: header-args :mkdirp true Below is an example of how to setup gnatsd cluster using Docker. I have put 3 different configurations (one per gnatsd server) under a folder named =conf= as follows: #+BEGIN_SRC sh :results output code tree conf #+END_SRC #+BEGIN_SRC sh conf |-- gnatsd-A.conf |-- gnatsd-B.conf `-- gnatsd-C.conf #+END_SRC Each one of those files have the following content below: (Here I am using ip =192.168.59.103= as an example, so just replace with the proper ip from your server) **** gnatsd-A #+BEGIN_SRC conf :tangle conf/gnatsd-A.conf # Copyright 2012-2015 Apcera Inc. All rights reserved. # Cluster Server A port: 7222 cluster { host: '0.0.0.0' port: 7244 routes = [ nats-route://192.168.59.103:7246 nats-route://192.168.59.103:7248 ] } #+END_SRC **** gnatsd-B #+BEGIN_SRC conf :tangle conf/gnatsd-B.conf # Copyright 2012-2015 Apcera Inc. All rights reserved. # Cluster Server B port: 8222 cluster { host: '0.0.0.0' port: 7246 routes = [ nats-route://192.168.59.103:7244 nats-route://192.168.59.103:7248 ] } #+END_SRC **** gnatsd-C #+BEGIN_SRC conf :tangle conf/gnatsd-C.conf # Copyright 2012-2015 Apcera Inc. All rights reserved. # Cluster Server C port: 9222 cluster { host: '0.0.0.0' port: 7248 routes = [ nats-route://192.168.59.103:7244 nats-route://192.168.59.103:7246 ] } #+END_SRC *** Starting the containers Then on each one of your servers, yo should be able to start the gnatsd image as follows: #+name: gnatsd-A #+BEGIN_SRC sh docker run -it -p 0.0.0.0:7222:7222 -p 0.0.0.0:7244:7244 --rm -v $(pwd)/conf/gnatsd-A.conf:/tmp/cluster.conf apcera/gnatsd -c /tmp/cluster.conf -p 7222 -D -V #+END_SRC #+name: gnatsd-B #+BEGIN_SRC sh docker run -it -p 0.0.0.0:8222:8222 -p 0.0.0.0:7246:7246 --rm -v $(pwd)/conf/gnatsd-B.conf:/tmp/cluster.conf apcera/gnatsd -c /tmp/cluster.conf -p 8222 -D -V #+END_SRC #+name: gnatsd-C #+BEGIN_SRC sh docker run -it -p 0.0.0.0:9222:9222 -p 0.0.0.0:7248:7248 --rm -v $(pwd)/conf/gnatsd-C.conf:/tmp/cluster.conf apcera/gnatsd -c /tmp/cluster.conf -p 9222 -D -V #+END_SRC