简体   繁体   English

Docker 透明网络和端口映射

[英]Docker Transparent Network and port mapping

I am trying to get a WCF application running in a docker windows container.我正在尝试让 WCF 应用程序在 docker windows 容器中运行。

I have played around with the different types of networking for a docker windows container.我已经尝试过 docker windows 容器的不同类型的网络。 Seems there are two main options NAT and Transparent.似乎有两个主要选项 NAT 和透明。

NAT is the default, and easily supports the -p 8080:80 type syntax to map a port. NAT 是默认设置,并且很容易支持-p 8080:80类型语法来映射端口。 However, NAT blocks me from accessing anything outside the computer.但是,NAT 阻止我访问计算机以外的任何内容。 (Meaning I cannot connect to other network resources.) (意味着我无法连接到其他网络资源。)

Transparent works great for accessing my network resources.透明非常适合访问我的网络资源。 But when I try to run it with -p 8080:80 it gives the following error:但是当我尝试使用-p 8080:80运行它时,会出现以下错误:

failed to create endpoint distracted_gates on network basic: hnsCall failed in Win32: 
Port mapping is not supported on the given network. (0x803b0016).

Seems "Port mapping is not supported" on Transparent networks.在透明网络上似乎“不支持端口映射”。

So, this leads to my question:所以,这引出了我的问题:

How do I specify a port to connect to my windows service using a Transparent network?如何指定端口以使用透明网络连接到我的 Windows 服务? (or is there a better way that I have not understood.) (或者有没有更好的方法我还没有理解。)

Note: In case it is relevant, here is my docker run command (that gives the above error message):注意:如果相关,这是我的 docker run 命令(给出上述错误消息):

docker run --network myTransparentNetwork --security-opt "credentialspec=file://mygMSA.json" -d -p 8080:80 myContainerImage:myTag

There is no need to map ports in a bridge (linux) or transparent (windows) networks.无需在网桥 (linux) 或透明 (windows) 网络中映射端口。 The requirement in this scenario is to make the use of the EXPOSE keyword within your Dockerfile.此场景中的要求是在EXPOSE使用EXPOSE关键字。

The EXPOSE keyword in most of the scenarios (where NAT is used) are more useful for documentation purposes once you still have to map your -p hostPort:containerPort .一旦您仍​​然需要映射您的-p hostPort:containerPort在大多数场景(使用 NAT 的情况下)中的EXPOSE关键字对于文档目的更有用。

See below an example of the EXPOSE keyword in the Dockerfile:请参阅以下EXPOSE关键字的示例:

#document ports that are mandatory
EXPOSE 8080 8090 9000

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

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