Azure容器实例:如何公开多个容器的同一端口?

发布于 2025-02-10 05:10:58 字数 1399 浏览 1 评论 0 原文

我不确定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服务?

I'm not sure what is port in Azure Container Instances and how it's used. I have 2 servers, that are both ASP.Net Core servers and must run together and talk to each other via sockets. This is YAML, that I used for deployment:

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

But I can not open 80 port for both servers. Because even after opening only one 80 port, I navigate in browser to ACI ip and do not see anything there. What does it even mean this ipAddress.ports in YAML config? And If it's not possible to do with ACI what Azure service should I use instead?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

很酷不放纵 2025-02-17 05:10:58

如果您想在同一主机端口上映射两个服务,我建议使用反向代理,例如 traefik nginx,haproxy,Envoy。强> 此服务的多个容器是在单个主机上创建的,端口将冲突。
反向代理将在当时聆听主机端口80,然后将其转发到端口上的特定Docker容器,该容器未映射到主机上,这取决于诸如Aliases,URL路径之类的一些特征规则。

在yaml config

中,这是什么意思

您可以使用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.

What does it even mean this ipAddress.ports in YAML config

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 explicitly bind() 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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文