Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploy docker on AWS beanstalk with docker composer

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.

What I know:

  1. I know I have to choose to deploy as multi-container docker.
  2. The best practice to manage multiple node.js services is using docker composer.
  3. I need a dockerrun.aws.json for node.js app.
  4. I need to create task definition for that ecs instance.

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. 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?
  3. I tried to run the task in ecs, but it stopped right away. How can I check the log for the task?

I got:

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

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:

{
  "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"
}
like image 760
RandomEli Avatar asked Jun 13 '16 16:06

RandomEli


2 Answers

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:

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.

Hope this helps.

like image 96
simdrouin Avatar answered Oct 14 '22 16:10

simdrouin


For me codecommit was no. Then after adding the Dockerrun.aws.json in git it works.

like image 34
Mamun Hasan Avatar answered Oct 14 '22 17:10

Mamun Hasan