Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker container IP address

Tags:

docker

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.

like image 249
shin Avatar asked Dec 02 '15 09:12

shin


People also ask

Does docker container have IP?

By default, the container is assigned an IP address for every Docker network it connects to. The IP address is assigned from the pool assigned to the network, so the Docker daemon effectively acts as a DHCP server for each container.

What IP is 172.17 0.1 docker?

Listen to Connections in the Docker Network The bridge connection docker0 – with IP address 172.17. 0.1 – is created by Docker at installation time. Because the host and all containers are connected to that network, our application only needs to listen to it.


1 Answers

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?

like image 191
mattinbits Avatar answered Oct 01 '22 11:10

mattinbits