5

I use Docker on Mac OSX.

After running a container, I check IP address.

docker inspect container-name | grep IP
"LinkLocalIPv6Address": "",
    "LinkLocalIPv6PrefixLen": 0,
    "SecondaryIPAddresses": null,
    "SecondaryIPv6Addresses": null,
    "GlobalIPv6Address": "",
    "GlobalIPv6PrefixLen": 0,
    "IPAddress": "172.17.0.5",
    "IPPrefixLen": 16,
    "IPv6Gateway": "",
            "IPAddress": "172.17.0.5",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0, 

Now when I go to 172.17.0.5, there is no response.

Then check IP address in another way.

docker-machine ip default
192.168.99.102

192.168.99.102 works.

Now my question is why it outputs different IP address and the first one doesn't work.

shin
  • 31,901
  • 69
  • 184
  • 271
  • Possible duplicate of [How to get a Docker container's IP address from the host?](https://stackoverflow.com/questions/17157721/how-to-get-a-docker-containers-ip-address-from-the-host) – Krunal May 09 '18 at 15:19

1 Answers1

5

the Docker daemon is linux-specific software, therefore to run on OS X, it must run inside a linux virtual machine. Using docker machine takes care of this for you. The IP address 172.17.0.5 is the address of that container on the docker bridge inside the linux virtual machine, and therefore it is not reachable from the OS X host machine.

The command docker-machine ip default returns the IP address of the virtual machine itself, which is reachable from the OS X Host machine.

If you SSH into the docker-machine virtual machine, then you would be able to reach 172.17.0.5 from within that SSH connection. For how to do this, see this answer: How to ssh into docker-machine VirtualBox instance?

Community
  • 1
  • 1
mattinbits
  • 10,370
  • 1
  • 26
  • 35
  • It's also worth noting that you can "expose" ports too. This means that if you would like to access port `80` from a device which is not the VM (in this case) you can do something like `-p 8080:80` (where `80` is the port within the container, and port `8080` is the port on the host). `192.168.99.102:8080` would then be accessible and route to `80` within the container. – Marcus Hughes Dec 02 '15 at 11:36