首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从Windows docker Container连接到主机系统Web API

从Windows docker Container连接到主机系统Web API
EN

Stack Overflow用户
提问于 2018-03-21 14:50:55
回答 1查看 555关注 0票数 0

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

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

已尝试使用以下地址访问API,但这些地址都不起作用。

代码语言:javascript
复制
https://host_system_ip:port/api/controller/action
代码语言:javascript
复制
https://default_gateway_ip:port/api/controller/action
代码语言:javascript
复制
https://localhost:port/api/controller/action
代码语言:javascript
复制
https://127.0.0.1:port/api/controller/action

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

EN

回答 1

Stack Overflow用户

发布于 2018-03-21 22:02:26

这对我来说在容器中工作得很好。确保您使用的是最新的操作系统等,并且没有丢失任何内容。

代码语言:javascript
复制
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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49399956

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档