在 AWS ECS 中设置 ulimit:HardLimit 不能为空

Setting ulimit in AWS ECS: HardLimit cannot be empty

根据官方说明 documentation and the official docker image 我是 运行 Elasticsearch 在本地使用这些配置通过 docker compose:

elasticsearch:
  image: 'elasticsearch:6.7.1'
  container_name: elasticsearch
  environment:
    - cluster.name=docker-cluster
    - bootstrap.memory_lock=true
    - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
  ulimits:
    memlock:
      soft: -1
      hard: -1
  volumes:
    - esdata1:/usr/share/elasticsearch/data
  ports:
    - 9200:9200

在本地成功 运行 我现在正在 EC2 和 Fargate 配置的 AWS ECS 中研究 运行 这个问题。那就是说我创建了一个 Cloudformation 模板,它有一个 TaskDefinition,它有一个用于 Elasticsearch 的 ContainerDefinition,看起来像这样:

ContainerDefinition:
  - Name: 'elasticsearch'
      Image: 'elasticsearch:6.7.1'
      LogConfiguration:
        LogDriver: awslogs
        Options:
          awslogs-group: !Ref 'LogGroup'
          awslogs-region: 'us-west-2'
          awslogs-stream-prefix: !Sub 'elasticsearch'
      Environment:
      - Name: cluster.name
        Value: 'docker-cluster'
      - Name: bootstrap.memory_lock
        Value: 'true'
      - Name: ES_JAVA_OPTS
        Value: '-Xms512m -Xmx512m'
      Cpu: '1024'
      Memory: '4096'
      Ulimits:
      - Name: 'memlock'
      - SoftLimit: -1
      - HardLimit: -1
      MountPoints:
      - SourceVolume: esdata1
        ContainerPath: /usr/share/elasticsearch/data
      PortMappings:
      - HostPort: '9200'
        ContainerPort: '9200'

使用此模板创建我的 Cloudformation 堆栈会导致以下 Cloudformation 错误:

CREATE_FAILED   AWS::ECS::TaskDefinition    TaskDefinition  Property HardLimit cannot be empty.

当我注释掉以下配置时:

  Ulimits:
  - Name: 'memlock'
  - SoftLimit: -1
  - HardLimit: -1

并开始创建我的 Cloudformation 堆栈,从 Cloudformation 的角度来看,一切都是成功的,没有遇到任何错误,这告诉我除了 Ulimits 配置之外,我应该做得很好。从那里我查看了 AWS Cloudformation ContainerDefinition documentation,其中提到了以下有关 Ulimits 配置的内容:

This parameter requires version 1.18 of the Docker Remote API or greater on your container instance.

我不确定为什么会收到此错误 HardLimit cannot be empty.,但想知道它是否与需要 Docker 远程 API 的容器有关。在这一点上我有点困惑,但如果有人有任何关于如何使这项工作的信息,我很想听听。我对 Docker Remote API 的了解并不多,也许这个错误与此无关。有时 Cloudformation 错误消息并不完全清楚,只是试图通过这一点,所以把我得到的所有信息都扔掉了。谢谢

您的 YML 配置有误。每次你有一个带有 - 的新行时,它都会创建一个新条目。在 JSON 格式中,您的 YML 看起来像:

  "Ulimits": [{
    "Name": "memlock"
  },{
    "SoftLimit": -1
  },{
    "HardLimit": -1
  }]

试试看:

  Ulimits:
  - Name: 'memlock'
    SoftLimit: -1
    HardLimit: -1