领事容器退出并出现协议版本错误

consul container exits with a protocol version error

我正在尝试为 consul 制作一个容器,但它总是失败并显示此输出,有趣的是,我真的不认为这是一个错误

Protocol 2 spoken by default, understands 2 to 3 (agent will automatically use protocol >2 when speaking to compatible agents)

以下是我正在使用的命令:

docker container run --net host --name consul-server -e 'CONSUL_LOCAL_CONFIG={"skip_leave_on_interrupt": true}' -e CONSUL_BIND_INTERFACE='eth0' consul agent -server -client 0.0.0.0 -dns-port 53 -bootstrap-expect 1 -ui -datacenter dc1 -v "/var/lib/consul:/consul/data" -data-dir /var/lib/consul

它是单节点全新安装,具有来自注册表的最新版本,因此没有升级或版本与此处发生的任何 agent/client 不匹配。

有两件事要解决。首先,-v volume 参数必须用于 docker 命令,而不是用于 consul 命令。将其移动到正确的位置:

docker container run -v "/consul/data:/var/lib/consul" -data-dir /var/lib/consul --net host --name consul-server -e 'CONSUL_LOCAL_CONFIG={"skip_leave_on_interrupt": true}' -e CONSUL_BIND_INTERFACE='eth0' consul agent -server -client 0.0.0.0 -dns-port 53 -bootstrap-expect 1 -ui -datacenter dc1 

同时反转它们(它们是 /host/dir:/container/dir)

其次,默认情况下,Consul 无法监听特权端口(即 53)。看到这个:https://www.consul.io/docs/guides/forwarding.html,所以删除 -dns-port 53 并实施他们推荐的任何方法:

docker container run -v "/consul/data:/var/lib/consul" -data-dir /var/lib/consul --net host --name consul-server -e 'CONSUL_LOCAL_CONFIG={"skip_leave_on_interrupt": true}' -e CONSUL_BIND_INTERFACE='eth0' consul agent -server -client 0.0.0.0 -bootstrap-expect 1 -ui -datacenter dc1 

我推荐DNSMasq setup,很容易实现。

@Robert 好吧,我想我们在这里也有点跑题了。真正的问题是它显示的消息并在那之后立即退出。

我试过你的例子,它给出了相同的结果message/error(不过不要认为这是一个错误)

[root@ip-X-X-X-X user]# docker container run --net host --name consul-server -e 'CONSUL_LOCAL_CONFIG={"skip_leave_on_interrupt": true}' -e CONSUL_BIND_INTERFACE='eth0' consul agent -server -client 0.0.0.0 -dns-port 53 -bootstrap-expect 1 -ui -datacenter dc1 -v "/var/lib/consul:/consul/data" -data-dir /var/lib/consul
==> Found address 'X.X.X.X' for interface 'eth0', setting bind option...
Consul v0.8.5
Protocol 2 spoken by default, understands 2 to 3 (agent will automatically use protocol >2 when speaking to compatible agents)
[root@ip-X-X-X-X user]# docker container ls | grep consul-server
[root@ip-10-201-14-34 user]#

递归示例相同:

[root@ip-X.X.X.X user]# docker container run --net host --name consul-server -e 'CONSUL_LOCAL_CONFIG={"skip_leave_on_interrupt": true}' -e CONSUL_BIND_INTERFACE='eth0' consul agent -server -client 0.0.0.0 -dns-port 53 -bootstrap-expect 1 -ui -datacenter dc1 -v "/var/lib/consul:/consul/data" -data-dir /var/lib/consul -recursers 8.8.8.8
==> Found address 'X.X.X.X' for interface 'eth0', setting bind option...
Consul v0.8.5
Protocol 2 spoken by default, understands 2 to 3 (agent will automatically use protocol >2 when speaking to compatible agents)
[root@ip-X-X-X-X user]# docker container ls | grep consul-server
[root@ip-10-201-14-34 user]#