registrator: Hosts IP Address Incorrect

  • What version of docker are you running?
Client:
 Version:      1.12.1
 API version:  1.24
 Go version:   go1.6.3
 Git commit:   23cf638
 Built:        Thu Aug 18 05:33:38 2016
 OS/Arch:      linux/amd64

Server:
 Version:      1.12.1
 API version:  1.24
 Go version:   go1.6.3
 Git commit:   23cf638
 Built:        Thu Aug 18 05:33:38 2016
 OS/Arch:      linux/amd64
  • What version of registrator are you running?
gliderlabs/registrator:latest 
  • Did you build a custom version of registrator? If so, what is that image? No
  • What is the exact command you are running registrator with?
docker run -d \
    --name=registrator \
    --net=host \
    --volume=/var/run/docker.sock:/tmp/docker.sock \
    gliderlabs/registrator:latest \
    consul://10.44.0.173:8500
  • What is the exact command you are running your container with?
docker run --rm -it \
    --network=bridge \
    --volume=/var/log/riemann-bridge:/log \
    -p :5555 \
    my-docker-riemann:latest
  • A log capture of all the docker events before, during, and after the issue.
2016/10/06 09:55:27 added: 660d29892e28 ip-10-4-38-156:big_brahmagupta:5555

Description of the problem:

Registrator registers services using containers ip instead of hosts. In consul service address appears as 172.17.0.4, where it should be 10.4.38.156.

...
"Service": {
      "ID": "ip-10-4-38-156:big_brahmagupta:5555",
      "Service": "docker-riemann",
      "Tags": null,
      "Address": "172.17.0.4",
      "Port": 32786,
      "EnableTagOverride": false,
      "CreateIndex": 586,
      "ModifyIndex": 586
    }
...

About this issue

  • Original URL
  • State: open
  • Created 8 years ago
  • Reactions: 1
  • Comments: 27

Most upvoted comments

I just wonder why I have to set -ip , registrator coundn’t get the host ip even if --net=host is set?

I faced this issue today for my AWS-ECS cluster. Until this issue gets fixed, here is a solution that might help some people. More information can be found in my stackoverflow post.

I modified my Dockerfile to execute a script at entrypoint and in that script I made the call to EC2 metadata service to get LOCAL_IP.

Dockerfile

FROM gliderlabs/registrator:v7

COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh && \
    apk update && \
    apk add curl

ENTRYPOINT ["/entrypoint.sh"]

entrypoint.sh

#!/bin/sh

LOCAL_IP=$(curl -s --connect-timeout 3 169.254.169.254/latest/meta-data/local-ipv4)
if [ $? -eq 0 ]; then
  /bin/registrator -ip $LOCAL_IP $@
else
  /bin/registrator $@
fi

You will notice the if-else condition above. If the curl command is a success, I am setting the ip flag inside so that I don’t have to pass the IP address in the cmd section. But for local testing where this curl command would fail, I am not setting any flags, and I will pass the ip flag in the cmd section.

Ended up using -ip flag, since I think registrator is having trouble picking up the right interface once dockerized.

Perhaps a good solution would be to pass REGISTRATOR_INTERFACE or similar env variable, to specify which interface to inspect.

Consul has this in their dockers ENTRYPOINT script.

Sorry gave you wrong command

docker run -d --net=host \
    -v /var/run/docker.sock:/tmp/docker.sock \
    gliderlabs/registrator \
       -ip <YOUR HOST IP> \
        consul://10.140.93.97:8500

it has to be passed to registrator rather than docker