RandomEli
RandomEli

Reputation: 1557

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"
}

Upvotes: 13

Views: 10327

Answers (7)

nbeuchat
nbeuchat

Reputation: 7111

In my case, I had not committed the Dockerrun.aws.json file after creating it, so using eb deploy failed with the same error.

Upvotes: 0

Jaap
Jaap

Reputation: 3220

I've had this issue as well. For me the problem was that Dockerrun.aws.json wasn't added in git. eb deploy detects the presence of git.

I ran eb deploy --verbose to figure this out:

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

It further lists all the files that'll go in to the zip, Dockerrun.aws.json isn't there.

git status reports this:

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)

Adding the file to git and committing helped. In my specific case I could just remove the .git directory in a scripted deploy.

Upvotes: 0

Remigiusz
Remigiusz

Reputation: 470

I got here due to the error. What my issue was is that I was deploying with a label using:

eb deploy --label MY_LABEL

What you need to do is deploy with ':

eb deploy --label 'MY_LABEL'

Upvotes: 0

Mamun Hasan
Mamun Hasan

Reputation: 41

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

Upvotes: 1

Chris
Chris

Reputation: 8442

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

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

Upvotes: 3

Sam H.
Sam H.

Reputation: 4359

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

Upvotes: 1

simdrouin
simdrouin

Reputation: 1018

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.

Upvotes: 9

Related Questions