You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure同一VM多端口Docker容器负载均衡配置咨询

How to Load Balance Multiple Docker Containers on the Same Azure VM (Different Ports)

Hey there! I get where you're coming from—Azure's load balancing model works a bit differently from AWS ALBs, so let's break down how to replicate your existing setup.

First, let's clear up a key constraint: Azure's standard/basic Load Balancer doesn't support mapping a single frontend port/protocol to multiple backend ports in one rule. Each load balancing rule is a strict 1:1 mapping between frontend (IP+port+protocol) and backend (pool+port). But don't worry, there are two solid ways to achieve your goal:

Option 1: Multiple Load Balancing Rules (for separate frontend ports)

If you can use distinct frontend ports to route traffic to each container (e.g., frontend port 80 → container port 8080, frontend port 81 → container port 8081), this is the simplest approach:

  • Create a Backend Pool: Add your target VM to this pool. Make sure the VM's network security group (NSG) allows inbound traffic on both container ports (8080 and 8081).
  • Create Health Probes: Set up two separate health probes—one for each container port. For example, a TCP probe on port 8080 and another on 8081, to ensure each container is healthy and reachable.
  • Create Load Balancing Rules:
    • Rule 1: Frontend port 80, protocol TCP, backend pool = your VM, backend port 8080, associate with the 8080 health probe.
    • Rule 2: Frontend port 81, protocol TCP, backend pool = your VM, backend port 8081, associate with the 8081 health probe.

This setup will route traffic hitting <your-public-ip>:80 to your first container, and <your-public-ip>:81 to the second.

Option 2: Azure Application Gateway (for same frontend port, content-based routing)

If you want to use a single frontend port (e.g., 80) and route traffic based on path or host headers (like AWS ALB's path-based routing), you'll need Azure Application Gateway—Azure's layer 7 load balancer, which matches the flexibility of AWS ALBs:

  • Set Up Backend Pool: Add your VM to the backend pool, then configure backend settings to include both container ports (8080 and 8081) as separate targets.
  • Configure Health Probes: Create dedicated probes for each container port to monitor their health status.
  • Create Routing Rules:
    • Define a listener for frontend port 80.
    • Build path-based routing rules:
      • Rule A: Path /app1/* → forward traffic to backend port 8080.
      • Rule B: Path /app2/* → forward traffic to backend port 8081.

Now, traffic to <your-public-ip>/app1 will go to your first container, and <your-public-ip>/app2 to the second—all using the same frontend port.

Quick Note on AWS vs Azure Differences

In AWS, you can add multiple ports from the same instance to a single target group, then route frontend traffic to that group. Azure's standard LB doesn't have this "multi-port target group" concept; instead, it relies on explicit 1:1 rules. Application Gateway is the closest Azure equivalent to AWS ALB for layer 7, content-aware routing scenarios.

Hope that clears things up—feel free to ask if you need help with any specific step!

内容的提问来源于stack exchange,提问作者bvnbhati

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 16:27:39