【问题标题】:Specifying launch type in docker-compose integration with ECS在与 ECS 的 docker-compose 集成中指定启动类型
【发布时间】:2022-11-25 11:09:47
【问题描述】:

关注compose-ECS integration documentation,并期待输出:

docker --context <my context> compose convert

...对于这个撰写文件:

version: "3.9"

services:
  web:
    image: "yeasy/simple-web:latest"

...我得到 ECS 服务的 Fargate 启动类型:


AWSTemplateFormatVersion: 2010-09-09
Resources:
  ...
  WebService:
    Properties:
      ...
      LaunchType: FARGATE
    ...
    Type: AWS::ECS::Service
...

看起来集成能够使用 EC2 启动类型,例如,如果我使用此撰写文件:

version: "3.9"

services:
  web:
    image: "yeasy/simple-web:latest"
    deploy:
      resources:
        reservations:
          generic_resources:
            - discrete_resource_spec:
                kind: gpus
                value: 2

...我得到:

AWSTemplateFormatVersion: 2010-09-09
Resources:
  ...
  WebService:
    Properties:
      ...
      LaunchType: EC2
    ...
    Type: AWS::ECS::Service
...

但是,我找不到任何方法来直接为服务指定 EC2 启动类型。这可能使用官方 docker 集成吗?

【问题讨论】:

    标签: docker docker-compose amazon-ecs


    【解决方案1】:

    docker-compose ECS 集成始终默认为 Fargate,唯一的例外是当您需要 GPU 时,目前只能通过 EC2 使用。

    如果您想对此进行更多控制,最好使用不同的工具来管理您的基础设施,例如 AWS CoPilot、Terraform 等。

    【讨论】:

      【解决方案2】:

      根据 Docker 文档:Tuning the CloudFormation template

      您可以在 Compose 文件中使用叠加层来更新或向将由 Docker Compose CLI 生成的 CloudFormation 添加属性。 它遵循相同的 CloudFormation 模板,您可以仅指定要更新或添加的属性。

      例如,您可以将以下 CloudFormation 覆盖属性添加到您的撰写文件中:

      此示例不完整,您可能必须指定实例类型和其他属性。

      version: "3.9"
      
      services:
        web:
          image: "yeasy/simple-web:latest"
      
      x-aws-cloudformation:
        Resources:
          WebService:
            Properties:
              LaunchType: EC2
          WebServiceTaskDefinition:
            Properties:
              RequiresCompatibilities: EC2
      

      要知道您需要更改哪些属性,首先您必须运行docker compose convert 以获取从您的 Compose 文件生成的 CloudFormation 文件,然后您可以查看CloudFormation documentation 并相应地更新/添加属性。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-08-17
        • 2020-12-21
        • 2019-02-15
        • 2020-07-04
        • 1970-01-01
        • 2019-07-27
        • 2016-05-26
        • 2022-10-14
        相关资源
        最近更新 更多