【问题标题】:Why can't ECS containers using `awsvpc` network mode declare `extraHosts` in CloudFormation?为什么使用 `awsvpc` 网络模式的 ECS 容器不能在 CloudFormation 中声明 `extraHosts`?
【发布时间】:2022-01-11 16:55:54
【问题描述】:

我希望能够使用 extraHosts 指令在 CloudFormation 中为我的 docker 容器声明其他主机。不幸的是,由于我使用的是 Fargate,这是不可能的,因为 Fargate 始终使用 awsvpc 网络模式。

为什么在 awsvpc 模式下无法在容器的 hosts 文件中声明额外的条目?不只是一个简单的额外电话--add-host在幕后吗?

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation amazon-ecs


    【解决方案1】:

    AWSVPC 模式是一种自定义模型,不使用基于标准容器的 docker 标志。换句话说,它们需要在“任务”级别重新实现(适用于任务内的所有容器),而我们根本没有实现这个标志(以及其他标志,例如 searchDomains)。

    在我的一个附带项目中,我通过使用读取变量并配置容器本身的脚本启动容器来解决此问题。该文件是here,为方便起见,我将其复制/粘贴到这里:

    #!/bin/bash
    
    # when the variable is populated a search domain entry is added to resolv.conf at startup
    # this is needed for the ECS service discovery given the app works by calling host names and not FQDNs
    # a search domain can't be added to the container when using the awsvpc mode 
    # and the awsvpc mode is needed for A records (bridge only supports SRV records)
    if [ $SEARCH_DOMAIN ]; then echo "search ${SEARCH_DOMAIN}" >> /etc/resolv.conf; fi 
    
    ruby /app/yelb-appserver.rb -o 0.0.0.0)
    

    GH issue 中有关于该主题的其他讨论。

    【讨论】:

      猜你喜欢
      • 2019-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-07
      • 2019-11-17
      • 2021-03-30
      • 2011-01-09
      • 2011-08-27
      相关资源
      最近更新 更多