Consul Docker#
Consul is a distributed, highly available, and data center aware solution to connect and configure applications across dynamic, distributed infrastructure.
Docker#
Configure and run a Consul server#
docker run \
-d \
-p 8500:8500 \
-p 8600:8600/udp \
--name=badger \
consul agent -server -ui -node=server-1 -bootstrap-expect=1 -client=0.0.0.0
docker run \
-d \
-p 8500:8500 \
-p 8600:8600/udp \
--name=badger \
hashicorp/consul agent -server -ui -node=server-1 -bootstrap-expect=1 -client=0.0.0.0
Discover the server IP address
docker exec badger consul members
Configure and run a Consul client#
docker run \
--name=fox \
consul agent -node=client-1 -retry-join=172.17.0.2
docker run \
--name=fox \
hashicorp/consul agent -node=client-1 -retry-join=172.17.0.2
Register a service#
docker run \
-p 9001:9001 \
-d \
--name=weasel \
hashicorp/counting-service:0.0.2
docker exec fox /bin/sh -c "echo '{\"service\": {\"name\": \"counting\", \"tags\": [\"go\"], \"port\": 9001}}' >> /consul/config/counting.json"
docker exec fox consul reload