Unable to run Registrator using docker-compose. Get connection refused error

别说谁变了你拦得住时间么 提交于 2019-12-11 04:43:50

问题


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.


回答1:


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
  ...


来源:https://stackoverflow.com/questions/41681944/unable-to-run-registrator-using-docker-compose-get-connection-refused-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!