使用 docker composer 在 AWS beanstalk 上部署 docker

Deploy docker on AWS beanstalk with docker composer

我正在尝试在 AWS beanstalk 上部署多个 node.js 微服务,我希望将它们部署在同一个实例上。我是第一次部署多个服务,所以有一些失败需要有人帮助我。因此,我尝试先将它们打包在 docker 容器中。同时,我正在使用 docker composer 来管理结构。它在我的虚拟机本地启动并 运行ning,但是当我将它部署到 beantalk 上时,我遇到了一些问题。

我知道的:

  1. 我知道我必须选择部署为多容器docker。
  2. 管理多个 node.js 服务的最佳做法是使用 docker composer。
  3. 我需要 dockerrun.aws.json 用于 node.js 应用。
  4. 我需要为该 ecs 实例创建任务定义。

我遇到的问题:

  1. 我只能找到 dockerrun.aws.jsontask_definition.json php 的模板,因此我无法验证我的配置是否适用于 node.js 这两个 json 文件的形状正确。
  2. docker-compose.ymldockerrun.aws.jsontask_definition.json 似乎在做类似的工作。我必须保持 task_definition,但我还需要dockerrun.aws.json吗?
  3. 我尝试 运行 ecs 中的任务,但它立即停止了。如何查看任务日志?

我得到了:

No ecs task definition (or empty definition file) found in environment

因为我的任务总是会立即停止。如果我能查看日志,我做问题排查就容易多了。

这是我的 task_definition.json:

{
  "requiresAttributes": [],
  "taskDefinitionArn": "arn:aws:ecs:us-east-1:231440562752:task-definition/ComposerExample:1",
  "status": "ACTIVE",
  "revision": 1,
  "containerDefinitions": [
    {
      "volumesFrom": [],
      "memory": 100,
      "extraHosts": null,
      "dnsServers": null,
      "disableNetworking": null,
      "dnsSearchDomains": null,
      "portMappings": [
        {
          "hostPort": 80,
          "containerPort": 80,
          "protocol": "tcp"
        }
      ],
      "hostname": null,
      "essential": true,
      "entryPoint": null,
      "mountPoints": [
        {
          "containerPath": "/usr/share/nginx/html",
          "sourceVolume": "webdata",
          "readOnly": true
        }
      ],
      "name": "nginxexpressredisnodemon_nginx_1",
      "ulimits": null,
      "dockerSecurityOptions": null,
      "environment": [],
      "links": null,
      "workingDirectory": null,
      "readonlyRootFilesystem": null,
      "image": "nginxexpressredisnodemon_nginx",
      "command": null,
      "user": null,
      "dockerLabels": null,
      "logConfiguration": null,
      "cpu": 99,
      "privileged": null
    }
  ],
  "volumes": [
    {
      "host": {
        "sourcePath": "/ecs/webdata"
      },
      "name": "webdata"
    }
  ],
  "family": "ComposerExample"
}

我遇到了类似的问题,结果证明我直接将包含的文件夹存档在我的 Archive.zip 文件中,因此在 Archive.zip 文件中给了我这个结构:

RootFolder
    - Dockerrun.aws.json
    - Other files...

事实证明,通过仅归档 RootFolder 的内容(而不是文件夹本身),Amazon Beanstalk 识别了 ECS 任务定义文件。

希望对您有所帮助。

类似的问题。为我修复它的是使用 CLI 工具而不是压缩自己,只是 运行 eb deploy 有效。

对我来说,这只是确保文件名与 AWS documentation.

中描述的大小写完全匹配的情况。

dockerfile.aws.json 必须正好是 Dockerfile.aws.json

对我来说,代码提交不是。然后在 git 中添加 Dockerrun.aws.json 之后就可以了。

由于错误,我来到这里。我的问题是我使用以下标签进行部署:

eb deploy --label MY_LABEL

您需要做的是使用 ':

进行部署
eb deploy --label 'MY_LABEL'

我也遇到过这个问题。对我来说,问题是 Dockerrun.aws.json 没有添加到 git 中。 eb deploy 检测到 git.

的存在

我运行eb deploy --verbose想弄明白:

INFO: Getting version label from git with git-describe
INFO: creating zip using git archive HEAD

它进一步列出了将进入 zip 的所有文件,Dockerrun.aws.json 不存在。

git status 报告:

On branch master
Your branch is up to date with 'origin/master'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    Dockerrun.aws.json

nothing added to commit but untracked files present (use "git add" to track)

将文件添加到 git 并提交有帮助。 在我的具体情况下,我可以删除脚本部署中的 .git 目录。

在我的例子中,我在创建 Dockerrun.aws.json 文件后没有提交它,所以使用 eb deploy 失败并出现同样的错误。