smebberson / docker-alpine

Docker containers running Alpine Linux and s6 for process management. Solid, reliable containers.
MIT License
596 stars 186 forks source link

How to determine the containers IP #41

Closed ncornag closed 8 years ago

ncornag commented 8 years ago

With the current method to obtain the container ip: getent hosts $HOSTNAME or even the new one: dig +short $HOSTNAME, there is no way to use an overlay network if it exists. And that's the case if you are using tools like Rancher to manage your containers. With Rancher you normally ask the rancher metadata to get that IP: curl -s http://rancher-metadata/latest/self/container/primary_ip. I think there should be some flexibility to obtain the IP to allow more use cases for the images.

Somehow related, specifying the dns server to obtain the consul ip also breaks the Rancher dns: dig +short consul @127.0.0.11

smebberson commented 8 years ago

Thanks for this issue. You raise a good point. I'll update the containers so that it's easier to change the method in which the current IP is retrieved. I'll move this functionality into a shell script in /usr/bin that can be used in all other scripts to determine the current IP. That will make it much easier to provide another method to retrieve the IP in non-standard environments such as Rancher.

Thanks for letting me know that the new method dig +short consul @127.0.0.11 also breaks on Rancher. I've got a hunch I don't need to use that IP specifically. I'll investigate this a little more.

I'll work on this change as part of the branch in which I'm working on a bunch of improvements to Consul. https://github.com/smebberson/docker-alpine/tree/alpine-consul-ui-upgrades

smebberson commented 8 years ago

@ncornag, any chance you could send me your /etc/resolv.conf file after one of your containers in Rancher starts up?

ncornag commented 8 years ago

Sure! / # cat /etc/resolv.conf nameserver 127.0.0.1 # added by go-dnsmasq search local micro-example.rancher.internal consul-ui.micro-example.rancher.internal rancher.internal

disabled by go-dnsmasq # nameserver 169.254.169.250

smebberson commented 8 years ago

@ncornag, have you found success in using the latest version of these containers by overriding /usr/bin/container-ip as found in alpine-base?

ncornag commented 8 years ago

Yes, it gives me a lot of flexibility.