Docker 组合 ECS 集成:负载均衡器属于应用程序类型,项目需要网络

Docker compose ECS integration: load balancer is of type application, project require a network

我有一个 docker-compose.yml 文件如下:

version: "3.8"
x-aws-loadbalancer: "arn:aws:elasticloadbalancing:my-load-balancer"
services:
  fastapi:
    image: username/auth:FastAPI
    x-aws-pull_credentials: "arn:aws:secretsmanager:us-west-2:creds"
    build: FastAPI
    ports:
      - "5555:5555"
  nginx:
    image: username/auth:nginx
    x-aws-pull_credentials: "arn:aws:secretsmanager:us-west-2:creds"
    build: nginx
    ports:
      - "80:80"
    depends_on:
      - fastapi
networks:
  default:
    external: true
    name: my-sg

但是当尝试使用 docker compose up 将它与 ECS 集成时,我收到错误:

load balancer "arn:aws:elasticloadbalancing:my-load-balancer" is of type application, project require a network

我也试过使用顶级 x-aws-vpc 属性 提供 vpc 并收到相同的错误。

什么

这是因为您正在使用端口 5555,docker-compose 无法知道该端口正在用于 HTTP,因此假设您需要网络负载均衡器,因为仅应用程序负载均衡器支持 HTTP。

对于 ECS docker-compose 集成,每个 the documentation

If services in the Compose file only expose ports 80 or 443, an Application Load Balancer is created, otherwise ECS integration will provision a Network Load Balancer. HTTP services using distinct ports can force use of an ALB by claiming the http protocol with x-aws-protocol custom extension within the port declaration:

因此,按照我链接的文档中的示例,我会尝试将您的 FastAPI 服务声明更改为以下内容:

  fastapi:
    image: username/auth:FastAPI
    x-aws-pull_credentials: "arn:aws:secretsmanager:us-west-2:creds"
    build: FastAPI
    ports:
      - "5555:5555"
        x-aws-protocol: http

或者将其更改为以下内容,以更接近文档中的示例:

ports:
  - target: 5555
    x-aws-protocol: http