gliderlabs / registrator

Service registry bridge for Docker with pluggable adapters
http://gliderlabs.com/registrator
MIT License
4.66k stars 912 forks source link

registering services with bridge networking mode is using internal ip #606

Open cs-mahmoud-khateeb opened 6 years ago

cs-mahmoud-khateeb commented 6 years ago

Docker version: 17.06.2-ce Registrator version: v7 (image: gliderlabs/registrator:latest) running in HOST networking mode. Consul version: Consul v1.0.3 (image: consul) running in HOST networking mode. Registrator command: /bin/registrator -internal=false consul://localhost:8500 Docker command: Command | ["-internal=false","consul://localhost:8500"]

Consul/Registrtor are working perfectly fine with services running on HOST networking mode, an example of this from /consul/data/services inside registrator container:

{"Token":"","Service":{"ID":"ip-172-30-x-x:ecs-consul-test-47-consul-server:53","Service":"consul","Tags":null,"Address":"","Port":53,"EnableTagOverride":false,"CreateIndex":0,"ModifyIndex":0}}
{"Token":"","Service":{"ID":"ip-172-30-x-x:ecs-rabbitmq-test-23-RabbitMQ:5672","Service":"rabbitmq","Tags":null,"Address":"","Port":5672,"EnableTagOverride":false,"CreateIndex":0,"ModifyIndex":0}}

The problem is happening when trying to discover services running on BRIDGE networking mode, an example of this is the following which is showing an internal docker address rather than showing the host address which is 172.30.x.x, the weird thing is that it showing the exposed port of the host:

{"Token":"","Service":{"ID":"ip-172-30-x-x:ecs-report-service:80","Service":"REPORT-80","Tags":null,"Address":"172.17.x.x","Port":33510,"EnableTagOverride":false,"CreateIndex":0,"ModifyIndex":0}}
[ec2-user@ip-172-30-x-x ~]$ dig @127.0.0.1 -p 53 report-80.service.consul. ANY
;; ANSWER SECTION:
report-80.service.consul. 0 IN  A   172.17.x.x

I was expecting it to give back the host ip 172.30.x.x:33510 rather than the internal docker ip 172.17.x.x:33510 espically that -internal=false.

Is there anything I am missing?

MartinMajor commented 6 years ago

I had exactly the same problem on AWS ECS. I tried to change network mode from bridge to default (which should be bridge too) and it works since then. I don't know why, so it is just a dirty workaround but it works for me.

cs-mahmoud-khateeb commented 6 years ago

@MartinMajor the setup I have is in AWS ECS. And that hack is the last thing I would ever think about! Thanks for sharing your solution. The way I have solved it is by passing the host IP to registrator upon start up and ask it to always use that IP. Ports aren't an issue as I mentioned in any of the networking mode.

hypolas commented 1 year ago

I can suggest to try that.

I done this option for myself with some rework on project: https://gitlab.com/dkr-registrator/registrator/