Knowledge

How to deploy multi-container Docker images to Elastic Beanstalk?

If your application consists of only one container, all you need is a Dockerfile in the repository: Elastic Beanstalk will use it to build the image and run the container with application.

However, if your app consists of more than one container (eg. you need to use docker compose to run it), then you need to add Dockerrun.aws.json with the configuration of your containers. Of course, the images must be built and pushed to the public registry first .

This article will show you how to automate the whole process with Buddy. The single-container version of the article is available here.

Set a Multi-Docker application in Elastic Beanstalk

  1. Log in to your AWS account
  2. Go to the Elastic Beanstalk service
  3. Add the application:

    • Select Web server as the Tier
    • Select Multi-container Docker as the Platform
    Setting up application in Elastic Beanstalk
    Setting up application in Elastic Beanstalk

Copy the Access key and the Secret key

To automate the deployment you need a user with the permission AWSElasticBeanstalkFullAccess so you can copy their Access and Secret keys. To create such user do the following:

  1. Log in to your AWS account
  2. Go to Users and click Add user
  3. Set the access type to Programmatic Access

    Creating new user
    Creating new user
  4. Look up and addAWSElasticBeanstalkFullAccess permission
  5. Once the user is added, download the CSV with its access details

    Adding permissions
    Adding permissions

Configure a pipeline in Buddy

Now you can create a pipeline that automatically build a Docker image on push to the repository, push it to the Docker Hub and deploy to Elastic Beanstalk. In this example we'll use this repository, a Node.JS app with Redis.

  1. Add a new project in Buddy and select GitHub as the provider.
  2. Choose the repository from the list:

    Selecting repository
    Selecting repository
  3. Add a new pipeline and set the trigger mode to On every push:

    Adding new pipeline
    Adding new pipeline
  4. Add the Docker build action that will build and push your image to the registry:

    Adding Docker build action
    Adding Docker build action
  5. Add the Upload to ElasticBeanstalk action

    • Copy and paste the Access and Secret keys from your AWS account
    • Select your AWS region and Application
    • Select Repository as the deployment source
    Adding upload to Elastic Beanstalk
    Adding upload to Elastic Beanstalk

When you're ready, make a push and watch Buddy build and deploy your Docker image.

Notes:

  • You can add an action that will build and test your application before deploying it to Elastic Beanstalk as a Docker image. In this case select the Filesystem as the source in the deployment action.
  • If you have more than one Dockerfile in the app, you can add a build action for every image.

Get started now

14 days of unlimited trial. No credit card required.