Consul dockerized

Hello there. I need to deliver a solution using HAproxy, consul-template and docker.

I came up with this structure running on AWS.

Instance A:
Running HAProxy and Consul-template and consul(bootstrap/leader). This instance will be my gateway load balance calls to the docker containers.

Instance B:
consul(server) and docker.
Multiple containers running consul and tomcat(REST service).

For these containers, in consul config, they should connect to the instance B consul, but I keep getting errors about the consul ports already in use, probably because there is a consul running in that instance.
How can I export and publish ports out of these containers and manage effective communication between then for the consul service?

Please help me gurus.

Please guys, help me…

It’s not really clear what you’re asking here. I strongly suggest familiarizing yourself with Docker’s networking model as outlined here:

With 1.10.* Docker will automatically create DNS entries for containers on same network.

To create connection between two containers on same host:

$ docker network create mynet
$ docker run -d --net mynet --name pinger alpine ping
$ docker run -ti --net mynet alpine ping -c 1 pinger
PING pinger ( 56 data bytes
64 bytes from seq=0 ttl=64 time=0.281 ms

--- pinger ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max = 0.281/0.281/0.281 ms

On multiple hosts use overlay driver when you docker network create (assumes you are talking to a Swarm endpoint and you have connected your Docker daemons via KV store).

You probably don’t need consul template directly if you use something like Interlock, but you must decide how to combine these primitives in whatever way works best for you.