Azure容器实例:如何公开多个容器的同一端口?
我不确定Azure容器实例中的端口是什么以及如何使用。我有2个服务器,它们都是ASP.NET核心服务器,必须通过插座一起运行并互相交谈。这是我用于部署的YAML:
apiVersion: 2019-12-01
location: westeurope
name: imgeneus-test
properties:
imageRegistryCredentials:
- server: imgeneusregistrytest.azurecr.io
username: imgeneusregistrytest
password: whatever
restartPolicy: OnFailure
containers:
- name: imgeneus-login
properties:
image: imgeneusregistrytest.azurecr.io/imgeneus.login:latest
resources:
requests:
cpu: 1
memoryInGb: 1
ports:
- port: 80 # 80 for web server, remove either this
- port: 30800 # 30800 for tcp communication
- name: imgeneus-world
properties:
image: imgeneusregistrytest.azurecr.io/imgeneus.world:latest
resources:
requests:
cpu: 1
memoryInGb: 1
ports:
- port: 80 # 80 for web server, or remove that
- port: 30810 # 30810 for tcp communication
osType: Linux
ipAddress:
type: Public
ports:
- protocol: tcp
port: 80
- protocol: tcp
port: 30800
- protocol: tcp
port: 30810
type: Microsoft.ContainerInstance/containerGroups
但是我无法为这两个服务器打开80个端口。因为即使仅打开一个80端口,我也会在浏览器中导航到ACI IP,并且在那里看不到任何东西。 YAML配置中的此 ipaddress.ports
这是什么意思?如果不可能使用ACI,我应该使用什么Azure服务?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想在同一主机端口上映射两个服务,我建议使用反向代理,例如 traefik nginx,haproxy,Envoy。强> 此服务的多个容器是在单个主机上创建的,端口将冲突。
反向代理将在当时聆听主机端口80,然后将其转发到端口上的特定Docker容器,该容器未映射到主机上,这取决于诸如Aliases,URL路径之类的一些特征规则。
您可以使用ACI IP本身,这意味着容器组的IP地址类型接受了私人,公共和要打开的端口列表的值。端口空间分隔列表默认值:[80] of az容器
也要制作服务器套接字
lincer()
在某个地址上,您需要明确bind()
它到接口和端口。将套接字绑定到(接口,端口)对是一个独家过程,重新检查您的许可和服务。供您参考:
If you want to map two services on same host port, i would suggest to use reverse proxy like Traefik or Nginx, HAProxy, Envoy. Multiple containers for this service are created on a single host, the port will clash.
The reverse proxy will listen the host port 80 at that point it forward to a particular docker container on port which are not mapped to the host depending a few characterized rules like aliases, URL path.
you can use ACI ip itself which means The IP address type of the container group accepted values of Private, Public and list of ports to open. Space-separated list of ports default value: [80] of az container
And also, To make a server socket
listen()
on a certain address, you need to explicitlybind()
it to an interface and port. Binding a socket to an (interface, port) pair was an exclusive process recheck your permission and services.For your Reference:
https://iximiuz.com/en/posts/multiple-containers-same-port-reverse-proxy/