14

I have a node.js application packaged in a docker image hosted in a public repository.

I have deployed that image in an AWS Beanstalk docker application successfully. The problem is that I was expecting the Beanstalk application to be automatically updated when I update the image in the public repository, as the following configuration sugggests.

Dockerrun.aws.json:

{
  "AWSEBDockerrunVersion": "1",
  "Image": {
    "Name": "peveuve/dynamio-payment-service",
    "Update": "true"
  },
  "Ports": [
    {
      "ContainerPort": "8000"
    }
  ],
  "Logging": "/var/log/dynamio"
}

The Dockerfile is very simple:

FROM node:4.2.1-onbuild
# Environment variables
ENV NODE_ENV test
ENV PORT 8000
# expose application port outside
EXPOSE $PORT

The Amazon documentation is pretty clear on that:

Optionally include the Update key. The default value is "true" and instructs Elastic Beanstalk to check the repository, pull any updates to the image, and overwrite any cached images.

But I have to update the Beanstalk application manually by uploading a new version of the Dockerrun.aws.json descriptor. Did I miss something? Is it supposed to work like that?

peveuve
  • 770
  • 8
  • 20

2 Answers2

10

You can use the aws command-line tool to trigger the update:

aws elasticbeanstalk update-environment --application-name [your_app_name] --environment-name [your_environment_name] --version-label [your_version_label]

You specify the version that contains the Dockerrun.aws.json file, that way a new version won't be added to the application. In this case the Dockerrun file works as the "source" for the application, but it only tells aws to pull the docker image, so it would be redundant to create new versions for the application in Elastic Beanstalk (unless you use specifically tagged docker images in the Dockerrun file)

Links:

http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_docker_image.html http://docs.aws.amazon.com/elasticbeanstalk/latest/api/API_UpdateEnvironment.htm

a544jh
  • 738
  • 9
  • 15
9

The documentation should be more clear. What they are saying is with update=true:

EBS will do a docker pull before it does a docker run when the application is first started. It will not continually poll docker hub.

In contrast, issuing a docker run without first doing a docker pull will always use the locally stored version of that machine, which may not always be the latest.

In order to acheive what you want, you'll need to set up a webhook on Docker Hub, that calls an application you control, that rebuilds your ELB app.

code_monk
  • 9,451
  • 2
  • 42
  • 41
  • I think you are basically right. I am just not sure a restart is enough, a rebuild is necessary. That's what I had to do, and another guy said the same thing in his blog. Upate your anwser if you agree and I will accept it. – peveuve Jan 14 '16 at 10:12
  • 2
    Update: actually, don't rebuild your app, it takes a very long time. Much better to upload the same Dockerrun.aws.json and increase the version number. – peveuve Mar 14 '16 at 09:03
  • See the answer of https://stackoverflow.com/a/41715702/3090068 ; it shows how to just re-do `docker pull` and `docker run`. – Yuki Inoue Mar 27 '18 at 09:10
  • 1
    Can I ask for more details? My dockerrun.aws.json uses a docker image `myimage:latest`. Whenever I re-deploy (by sending `eb deploy` from eb-cli), the currently latest image is pulled and started. How can I automate this `eb deploy` ? Doesn't the `aws elasticbeanstalk update-environment ...` need to be issued manually as well? – olidem May 22 '19 at 06:05