如何从Windows 10上的容器(Docker for Windows)连接到Docker主机 [英] How to connect to docker host from container on Windows 10 (Docker for Windows)
问题描述
泊坞窗容器可以在哪个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 .
在Windows的Docker中,容器通过称为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地址就是您需要的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.
这篇关于如何从Windows 10上的容器(Docker for Windows)连接到Docker主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!