0

我在主机系统上运行一个 Web API,它没有暴露在公共 IP 上。我想从在同一系统上运行的 docker windows 容器访问。

通过初步分析,windows 容器似乎不支持从容器内访问主机系统。

尝试使用以下地址访问 API,但它们都不起作用。

https://host_system_ip:port/api/controller/action
https://default_gateway_ip:port/api/controller/action
https://localhost:port/api/controller/action
https://127.0.0.1:port/api/controller/action

出于安全原因,我无法在公共 IP 上访问该 API,应该允许在同一主机上运行的唯一主机系统和容器访问 Web API。

4

1 回答 1

0

这在容器内对我来说很好。确保您使用的是最新的操作系统等,并且没有遗漏任何东西。

PS C:\> docker run --rm microsoft/windowsservercore powershell invoke-webrequest 192.168.1.221 -useBasicParsing


StatusCode        : 200
StatusDescription : OK
Content           : Application 995184 and started on 3/21/2018 8:59:09 AM
RawContent        : HTTP/1.1 200 OK
                    Content-Length: 54
                    Cache-Control: private
                    Content-Type: text/html; charset=utf-8
                    Date: Wed, 21 Mar 2018 14:01:22 GMT
                    Server: Microsoft-IIS/10.0
                    X-AspNet-Version: 4.0.30319
                    X-Pow...
Forms             :
Headers           : {[Content-Length, 54], [Cache-Control, private],
                    [Content-Type, text/html; charset=utf-8], [Date, Wed, 21
                    Mar 2018 14:01:22 GMT]...}
Images            : {}
InputFields       : {}
Links             : {}
ParsedHtml        :
RawContentLength  : 54



PS C:\> ipconfig

Windows IP Configuration


Ethernet adapter vEthernet (nat):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::94d6:434:c0b6:8fdc%56
   IPv4 Address. . . . . . . . . . . : 172.29.112.1
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Default Gateway . . . . . . . . . :

Ethernet adapter vEthernet (Internet):

   Connection-specific DNS Suffix  . : lan
   Link-local IPv6 Address . . . . . : fe80::342a:be30:c7c:c1de%24
   IPv4 Address. . . . . . . . . . . : 192.168.1.221
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.1.1
于 2018-03-21T14:02:25.963 回答