如何从 Windows 10 上的容器连接到 docker 主机(Docker for Windows)
docker 容器可以通过哪个 IP 地址连接到 Docker for Windows 上的主机(在 Windows 10 上)?你如何找到这个IP地址?
At which IP address can a docker container connect to its host on Docker for Windows (on Windows 10)? How do you find this IP address?
示例:您在 Windows 10 计算机上的端口 1234 上运行了一项服务.容器内的程序必须访问此服务.程序应该使用什么 IP 地址连接到主机?
Example: you have a service running at port 1234 on your Windows 10 machine. A program inside your container must access this service. What IP address should the program use to connect to the host?
简短回答:在大多数情况下,您需要 10.0.75.1.
Short answer: in most cases, you'll need 10.0.75.1 .
在 Docker for Windows 中,容器通过称为 DockerNAT 的 vEthernet 适配器进行通信.要查找其详细信息,请打开命令提示符并键入
In Docker for Windows, the container communicates through a vEthernet adapter called DockerNAT. To find its details, open Command Prompt and type
ipconfig
查找类似于
Ethernet adapter vEthernet (DockerNAT):
Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::fd29:297:4583:3ad4%4
IPv4 Address. . . . . . . . . . . : 10.0.75.1
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . :
IPv4 Address
右边的IP地址就是你需要的.
The IP address to the right of IPv4 Address
is the one you need.
注意:确保服务允许来自主机外部的连接.就该服务而言,您的 docker 容器是一台不同的机器.还要确保 Windows 防火墙允许与服务进行通信.
Note: make sure the service allows connections from outside your host. As far as that service is concerned, your docker container is a different machine. Also make sure Windows Firewall allows communication to and from the service.