如何解决 Amazon ECS 中的“ was unable to place a task because no container instance met all of its requirements”错误?

上次更新时间:2019 年 7 月 3 日

当我尝试在 Amazon Elastic Container Service (Amazon ECS) 中放置任务时,收到以下错误:“ was unable to place a task because no container instance met all of its requirements.” 如何解决此错误?

简短描述

您可能会由于以下问题之一收到此错误:

在您的集群中未找到任何容器实例 该任务所需的端口已被占用 内存不足以完成任务 可用于您的容器实例的 CPU 单元不足 没有足够的弹性网络接口 (ENI) 连接点 容器实例缺少必需属性

有关这些问题的更多信息,请参阅服务事件消息。

注意:如果您没有收到上述错误消息,请根据您收到的以下错误消息选择文章:

was unable to place a task because no container instance met all of its requirements.The closest matching container-instance container-instance-id has insufficient CPU units available. was unable to place a task because no container instance met all of its requirements.The closest matching container-instance container-instance-id encountered error "AGENT".

解决方法

要解决该错误,请根据以下问题之一选择解决方案:

如果集群中未注册任何容器实例,则将容器实例添加到集群。 如果任务所需的端口被占用,则将容器实例添加到集群,或者减少所需任务的数量。
注意:如果可能,请考虑使用动态端口映射,以允许任务使用容器实例上的任何可用端口。 如果容器实例没有足够的内存用于任务,则减少任务定义中的内存量,或在集群中启动更多容器实例。
注意:有关更多信息,请参阅服务事件消息中的内存不足一节。 如果容器实例没有足够的 CPU 单元,则调整 CPU 所需的任务,或者在集群中启动更多容器实例。
注意:有关更多信息,请参阅服务事件消息中的 CPU 不足一节。或者,请参阅如何解决 Amazon ECS 中的“The closest matching container-instance container-instance-id has insufficient CPU units available”错误? 如果容器实例没有任何可用的 ENI 连接点,则向集群添加更多容器实例。
注意:有关更多信息,请参阅服务事件消息中的没有足够的可用 ENI 附加点一节。如果问题仍然存在,请考虑使用awsvpcTrunking。这将增加您的 EC2 实例上的 ENI 密度。 如果容器实例缺少必需属性,则请参阅服务事件消息中的容器实例缺少必需属性一节。要查找缺失的属性,请使用 ecs-cli check-attributes 命令。
注意:有关特定任务定义参数和代理配置变量所需属性的更多信息,请参阅任务定义参数和 Amazon ECS 容器代理配置。