3

I'm wanting to make a connection back to the email server on the host computer from within the docker. Right now, I can do ifconfig and get the ip from the docker0 device, but that requires manual intervention to set the IP within the docker. And if the docker image is saved and copied to a new server, that IP might not be the same.

Is there some way to get the internal host IP (from docker0) from within the docker at runtime (maybe from the environment)?

At the moment I don't see it as part of the environment, so I'm wondering if I have to something during docker setup to enable it.

1

Instead of trying to get the address from the host, why not run dhcp inside the container ? e.g. add

auto eth0
iface eth0 inet dhcp

inside /etc/network/interfaces and then do /etc/init.d/network restart

5
  • I'm trying to get the IP of the host, not the docker. How would changing it to dhcp accomplisth that? – boatcoder Aug 26 '14 at 15:16
  • Does run --env <key>=<value> work ? I guess not as it changes often. Or try "/sbin/ip route|awk '/default/ { print $3 }'" to get the default route (hopefully the host) – Neil McGill Aug 26 '14 at 15:44
  • It's sounding more and more like finding that address is not going to be easy.. – boatcoder Aug 26 '14 at 16:25
  • /sbin/ip route|awk '/default/ { print $3 }' | head -1 - worked for me and it has the advantage that it will work with and without a host container. It's just getting your default route which should be the host... – Neil McGill Aug 26 '14 at 16:30
  • That did it. Don't know why that didn't occur to me. Thanks. – boatcoder Aug 27 '14 at 18:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.