0

If I start a docker container, I can for some reason access the docker host's services if I use the host's LAN ip, eg:

docker run -it ubuntu sh -c "apt-get update && apt-get install -y netcat && nc -z 192.168.196.135 3449"

But how do I know which IP to access the host on? Running ifconfig doesn't show any networks in the 192.x range. What if the host is disconnected from the LAN?

Grav
  • 1,714
  • 14
  • 27
  • 1
    Seems I can normally get it using `docker-machine ip`, but docker-machine doesn't work when using Docker for Mac. – Grav Jul 04 '16 at 12:42
  • What about `pinata list` that I mentioned this morning in http://stackoverflow.com/a/38178195/6309? Or (other option) http://stackoverflow.com/a/24716645/6309? – VonC Jul 04 '16 at 13:25

1 Answers1

1

You can add a entry to your container's /etc/hosts

docker run --add-host="dockerhost:192.168.196.135" -it ubuntu sh -c "apt-get update && apt-get install -y netcat && nc -z dockerhost 3449"

You also can use this docker discovery agent

If you need something more sophisticated then that you'll need a service discovery system like zookeeper.

Rogério Peixoto
  • 2,176
  • 2
  • 23
  • 31