Consul with Docker : very basic

Start a consul container as a server agent

Command :
docker run -d -p 8500:8500 -p 8600:8600/udp --name=consul-server consul agent -server -ui -node=server1 -bootstrap-expect=1 -client=0.0.0.0

Explanations :
– Ports are published only to bring helpful tools directly accessible from the docker host (mainly Consul DNS and Consul UI).
– 8500 is port used by the Consul HTTP API and UI. We publish it to interact with the UI from localhost of the host.
– 8600 is port used for the consul DNS server (TCP and UDP). We publish it to query with the DNS from the localhost.
– bootstrap-expect=1 allows to bootstrap the datacenter as soon as the docker container is started (not good in production).
– client=0.0.0.0 makes the local agent listen any IP. This allows you to work with the Consul agent directly from the host.

Start a consul container as a client agent that joins the server agent

Before all, we need to know the ip address of the server agent.
We could know that in multiple ways :
– read the startup logs (docker logs consul-server) of the server agent container and look for the « Cluster Addr » value. That looks like :
Cluster Addr: 172.17.0.3 (LAN: 8301, WAN: 8302)
– query the ip address of hostname with : docker exec consul-server hostname -i
– inspect the docker server agent container with docker inspect consul-server | grep IPAddress
Supposing that the cluster address of the server agent is 172.17.0.3, here is the command to run the client agent to join it :
docker run -d --name=consul-client-1 consul agent -node=client1 -join=172.17.0.3

Explanations : not really required here.
Note that we don’t publish port for the UI or the DNS because we have already done that for the server agent. That is really enough to help diagnostic.

Ce contenu a été publié dans Non classé. Vous pouvez le mettre en favoris avec ce permalien.

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *