问题描述
我在本地机器上有领事和一些服务。现在我想使用注册商在Consul实施服务注册。如果我这样做:$ docker run -d --name registrator --net = host \
之后,运行一些服务,我看到他们已经在领事馆注册了pre>
--volume /var/run/docker.sock:/tmp/docker.sock gliderlabs / registrator \
consul://127.0.0.1:8500
然而,如果我尝试通过docker-compose.yml(因为我不想每次手动运行上面的命令)来执行它:
version:'2'
services:
consul:
image:gliderlabs / consul-server:latest
command:advertise = 127.0.0.1 -server -bootstrap
container_name:consul
hostname:127.0.0.1
ports:
- 8500:8500
registrator:
image:gliderlabs / registrator:latest
命令:consulL // 127.0.0.1:8500
container_name:registrator
主机名:127.0.0.1
depends_on:
- consul
卷:
- /var/run/docker.sock:/tmp/docker.sock
...需要注册的其他服务
并运行:
$ docker-compose up
然后我在控制台看到这个错误信息:
registrationrator | 2017/01/16 17:01:24获取http://127.0.0.1:8500/v1/status/leader拨打tcp 127.0.0.1:8500:连接拒绝
我猜,我的问题与事实有关,我没有指定
- net = host
。但是我不知道该怎么做我希望有人知道如何解决它。解决方案Docker-compose为<$ c $中的所有服务创建新的网络c> docker-compose.yml 默认情况下。如果您需要将您的容器附加到主机网络,请添加到您的服务网络模式参数:
...
注册器:
network_mode:host
...
I have Consul and a bunch of services on my local machine. Now I want to implement service registration in Consul using Registrator. If I do it like so:
$ docker run -d --name registrator --net=host \ --volume /var/run/docker.sock:/tmp/docker.sock gliderlabs/registrator \ consul://127.0.0.1:8500
And after that run some services, I see that they are registered in Consul. If however I try to do it via docker-compose.yml (since I do not want to run the above command each time by hand):
version: '2' services: consul: image: gliderlabs/consul-server:latest command: "advertise=127.0.0.1 -server -bootstrap" container_name: consul hostname: 127.0.0.1 ports: - "8500:8500" registrator: image: gliderlabs/registrator:latest command: "consulL//127.0.0.1:8500" container_name: registrator hostname: 127.0.0.1 depends_on: - consul volumes: - /var/run/docker.sock:/tmp/docker.sock ... other services that need to be registered
And run:
$ docker-compose up
then I see in the console this error message:
registrator | 2017/01/16 17:01:24 Get http://127.0.0.1:8500/v1/status/leader dial tcp 127.0.0.1:8500: connection refused
I guess, my problem is related to the fact, that I didn't specify
--net=host
. But I do not know how can I do that. I hope, someone knows how to fix it.解决方案Docker-compose creates new network for all your services in
docker-compose.yml
by default. If you need to attach your container to host network add to your service network mode param:... registrator: network_mode: host ...
这篇关于无法使用docker-compose运行注册器。获取连接拒绝错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!