Analysis of Docker deployment Consul configuration process
- 2021-09-20 21:56:40
- OfStack
Execute a command
docker run -d --name consul -p 8500:8500 consul
Port description
https://www.consul.io/docs/install/ports.html
Mount instructions
/consul/data: Persistent data store
/consul/config: Configuration file
Consul Configuration
https://www.consul.io/docs/agent/options.html
Note: Browser opens http://Public ip: 8500
Cluster deployment
Start 4 Consul Agent, 3 Server (1 leader will be elected) and 1 Client
# Start the first Server node, cluster requires three Server, map container 8500 port to host 8900 port, and open the management interface at the same time
docker run -d --name=consul1 -p 8900:8500 -e CONSUL_BIND_INTERFACE=eth0 consul agent --server=true --bootstrap-expect=3 --client=0.0.0.0 -ui
# Start the second Server node and join the cluster
docker run -d --name=consul2 -e CONSUL_BIND_INTERFACE=eth0 consul agent --server=true --client=0.0.0.0 --join 172.17.0.2
# Start the third Server node and join the cluster
docker run -d --name=consul3 -e CONSUL_BIND_INTERFACE=eth0 consul agent --server=true --client=0.0.0.0 --join 172.17.0.2
# Start the 4th Client node and join the cluster
docker run -d --name=consul4 -e CONSUL_BIND_INTERFACE=eth0 consul agent --server=false --client=0.0.0.0 --join 172.17.0.2
The IP1 of the first startup container is generally 172.17. 0.2, and the subsequent startup containers IP will be lined up: 172.17. 0.3, 172.17. 0.4, 172.17. 0.5.
These Consul nodes are interoperable within the Docker container, and they communicate through bridged patterns. However, if the host wants to access the network within the container, it needs to do port mapping. When starting the first container, the 8500 port of Consul is mapped to the 8900 port of the host, so that the cluster information can be easily viewed through the browser of the host.