我们在也运行服务的主机上使用了一个consul代理.(RabbitMQ)为了验证服务是否准备就绪,我们已经定义了基于卷曲的运行状况检查.但是,我们使用registrator使用env变量注入此检查.SERVICE_CHECK_SCRIPT =卷曲hostname
:15672/....
问题是,我们还告诉consul-agent其主机名与主机相同.(我们必须拥有此功能,因为我们希望看到向consul集群注册的正确主机名.
当consul代理运行运行状况检查时,它会在自己的容器中查找URL ...这显然会失败...是否有人知道如何定义此运行状况检查(我们使用mesos来执行此操作)以便curl将尝试连接到正确的IP?
您可以使用Registrator的HTTP运行状况检查(前提是您在progrium/docker-consul
容器内运行Consul ),例如:
ENV SERVICE_CHECK_HTTP=/howareyou
ENV SERVICE_CHECK_INTERVAL=5s
此检查将运行由提供的check-http脚本docker-consul
,该脚本使用Docker API 解析目标容器的IP和端口.
The other option is to configure Consul DNS to listen on Docker's bridge IP (which is already done in progrium/docker-consul
's run
script), and launch Docker daemon with the global DNS option pointing to the same IP, e.g. docker -d --bip 10.0.42.1/24 --dns 10.0.42.1 --dns 8.8.8.8
.
After that Consul DNS will be available in any of your containers, including the docker-consul
one, which means that you can run curl http://my-app.service.consul:12345/howareyou
, or even query SRV
records, e.g. with dig -t SRV
, to obtain both IP and port of a service. And then you may add 10.0.42.1
to the host's resolv.conf
to gain the ability to query Consul DNS not only within containers, but from the host OS too.
The preferred method, imho, is to use Registrator's SERVICE_CHECK_HTTP
, but setting up Consul DNS for your containers is worth doing anyway.
Both these methods require running Consul agent in client mode on each of your application hosts, but Consul agent, when ran in this mode, uses such a tiny amount of system resources that you'll hardly notice it. And you need it anyway to perform health checks :)