简体   繁体   English

Docker容器IP地址

[英]Docker container IP address

I use Docker on Mac OSX. 我在Mac OSX上使用Docker。

After running a container, I check IP address. 运行容器后,我检查IP地址。

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. 现在当我转到172.17.0.5时,没有回应。

Then check IP address in another way. 然后以另一种方式检查IP地址。

docker-machine ip default
192.168.99.102

192.168.99.102 works. 192.168.99.102有效。

Now my question is why it outputs different IP address and the first one doesn't work. 现在我的问题是为什么它输出不同的IP地址,第一个不起作用。

the Docker daemon is linux-specific software, therefore to run on OS X, it must run inside a linux virtual machine. Docker守护程序是特定于Linux的软件,因此要在OS X上运行,它必须在linux虚拟机中运行。 Using docker machine takes care of this for you. 使用docker机器为您完成这项工作。 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. IP地址172.17.0.5是linux虚拟机内docker bridge上该容器的地址,因此无法从OS X主机访问它。

The command docker-machine ip default returns the IP address of the virtual machine itself, which is reachable from the OS X Host machine. 命令docker-machine ip default返回虚拟机本身的IP地址,该地址可从OS X主机访问。

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. 如果您通过SSH连接到docker-machine虚拟机,那么您将能够从该SSH连接中访问172.17.0.5 For how to do this, see this answer: How to ssh into docker-machine VirtualBox instance? 有关如何执行此操作,请参阅以下答案: 如何ssh到docker-machine VirtualBox实例?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM