【问题标题】:Elastic Beanstalk Multicontainer Docker environment: no entries in etc/hosts for lined containersElastic Beanstalk 多容器 Docker 环境:在 etc/hosts 中没有内衬容器的条目
【发布时间】:2016-11-22 09:29:36
【问题描述】:

我有一个包含几个容器的环境。其中一些是相互关联的。当我使用“docker-compose up -d”运行环境时,它会在 etc/hosts 中为链接的容器创建条目。当我使用“eb local run”运行它时,不会创建任何条目。这是为什么呢?

我的 Dockerrun.aws.json

{
      "AWSEBDockerrunVersion": 2,
      "containerDefinitions": [
        {
          "name": "api",
          "image": "php7",
          "essential": true,
          "memory": 128,
          "portMappings": [
            {
              "hostPort": 8080,
              "containerPort": 80
            }
          ],
          "mountPoints": [
            {
              "sourceVolume": "api",
              "containerPath": "/var/www/html/"
            }
          ]
        },
        {
          "name": "nodeapi",
          "image": "nodejs",
          "essential": true,
          "memory": 256,
          "portMappings": [
            {
              "hostPort": 5000,
              "containerPort": 5000
            }
          ],
          "mountPoints": [
            {
              "sourceVolume": "nodeapi",
              "containerPath": "/var/www/app/"
            }
          ],
          "Logging": "/var/eb_log"
        },
        {
          "name": "proxy",
          "image": "nginx",
          "essential": true,
          "memory": 128,
          "links": [
            "api",
            "nodeapi"
          ],
          "portMappings": [
            {
              "hostPort": 8443,
              "containerPort": 80
            }
          ]
        }
      ]
    }

这会生成 docker-compose.yml:

    api:
      image: php7
      ports:
      - 8080:80
    nodeapi:
      image: nodejs
      ports:
      - 5000:5000
    proxy:
      image: nginx
      links:
      - api:api
      - nodeapi:nodeapi
      ports:
      - 8443:80

【问题讨论】:

    标签: amazon-web-services docker amazon-elastic-beanstalk


    【解决方案1】:

    Docker 不久前切换到基于 DNS 的查找,而不是向 /etc/hosts 添加条目。也不鼓励使用链接,而是为容器使用公共网络。

    【讨论】:

    • 感谢您的回答。我的 docker 版本是 1.9.1。你是说如果我升级到最新版本,使用 docker-compose 时链接将不再起作用?
    • 这仍然是一个选项,只是不建议继续使用。 DNS 发现是在 2 月发布的 1.10 中添加的。
    • 好的,谢谢。但是你知道为什么 EB Multicontainer Docker 环境不为那些指向 etc/hosts 的链接添加别名,而 docker-compose 可以吗?
    • 我不确定 AWS 的具体实施,您是否尝试过使用 DNS 解决您的问题?
    【解决方案2】:

    好的,这是本地问题。我将 Docker 和 EB cli 升级到了最新版本,这解决了这个问题。我不确定为什么 EB cli 之前未能向 etc/hosts 添加别名,但在升级后它确实如此。现在我通过使用“docker-compose up”或“eb local run”得到相同的结果。所有链接的容器现在都已链接并按预期工作。

    【讨论】:

      猜你喜欢
      • 2017-12-26
      • 2020-08-28
      • 2017-07-26
      • 1970-01-01
      • 2018-06-20
      • 2017-10-14
      • 2016-02-28
      • 2017-07-04
      • 2016-08-17
      相关资源
      最近更新 更多