阅读背景:

使用docker composer在AWS beanstalk上部署docker

来源:互联网 

I'm trying to deploy multiple node.js micro services on AWS beanstalk, and I want them to be deployed on the same instance. It's my first time to deploy multiple services, so there're some failures I need someone to help me out. So, I tried to package them in a docker container first. Meanwhile I'm using docker composer to manage the structure. It's up and running locally in my virtual machine, but when I deployed it on to beanstalk, I met a few problems.

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

What I know:

我知道的:

  1. I know I have to choose to deploy as multi-container docker.
  2. 我知道我必须选择部署为多容器docker。
  3. The best practice to manage multiple node.js services is using docker composer.
  4. 管理多个node.js服务的最佳实践是使用docker composer。
  5. I need a dockerrun.aws.json for node.js app.
  6. 我需要一个用于node.js app的dockerrun.aws.json。
  7. I need to create task definition for that ecs instance.
  8. 我需要为该ecs实例创建任务定义。

Where I have problems:

哪里有问题:

  1. I can only find dockerrun.aws.json and task_definition.json template for php, so I can't verify if my configuration for node.js in those two json files are in correct shape.
  2. 我只能找到php的dockerrun.aws.json和task_definition.json模板,所以我无法验证这两个json文件中node.js的配置是否正确。
  3. It seems like docker-compose.yml, dockerrun.aws.json and task_definition.json are doing similar jobs. I must keep task_definition, but do I still need dockerrun.aws.json?
  4. 似乎docker-compose.yml,dockerrun.aws.json和task_definition.json正在做类似的工作。我必须保持task_definition,但是我还需要dockerrun.aws.json吗?
  5. I tried to run the task in ecs, but it stopped right away. How can I check the log for the task?
  6. 我试图在ecs中运行任务,但它立即停止了。如何查看日志以查找任务?

I got:

我有:

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

在环境中找不到ecs任务定义(或空定义文件)

because my task will always stop immediately. If I can check the log, it will be much easier for me to do trouble shooting.

因为我的任务将永远停止。如果我可以查看日志,我会更容易进行故障排除。

Here is my task_definition.json:

这是我的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"
}

3 个解决方案

#1


5  

I had a similar problem and it turned out that I archived the containing folder directly in my Archive.zip file, thus giving me this structure in the Archive.zip file:

我有一个类似的问题,结果我直接在Archive.zip文件中存档包含文件夹,从而在Archive.zip文件中给我这个结构:

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

It turned out that by archiving only the RootFolder's content (and not the folder itself), Amazon Beanstalk recognized the ECS Task Definition file.

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

Hope this helps.

希望这可以帮助。

#2


1  

Similar problem. What fixed it for me was using the CLI tools instead of zipping myself, just running eb deploy worked.

类似的问题。为我修复它的原因是使用CLI工具而不是自己压缩,只需运行eb deploy就可以了。

#3


1  

For me, it was simply a case of ensuring the name of the file matched the exact casing as described in the AWS documentation.

对我来说,这只是一个确保文件名称与AWS文档中描述的确切外壳匹配的情况。

dockerfile.aws.json had to be exactly Dockerfile.aws.json

dockerfile.aws.json必须完全是Dockerfile.aws.json


分享到: