Deploy a multi-container app to AWS EB
Metin Yazici
2020-02-20 - 2 years ago
2 min read

⚠️ Depreciation notice: As of Oct 2020,1 the Elastic Beanstalk Docker on Amazon Linux 2 platform supports docker-compose.yml file format to define and run multiple containers. The migration documentation2 is for how to transform Dockerrun.aws.json to docker-compose.yml.


In this post, I explain how to deploy a multi-container Docker application to the AWS Elastic Beanstalk service3.

We have the following folder structure:

.
├── backend
│   └── app.py
├── config
│   └── nginx
│       └── nginx.conf
└── Dockerfile

The config below is for deploying a Flask application (under backend/app.py) together with the nginx reverse proxy service.

Dockerrun.aws.json
{
  "AWSEBDockerrunVersion": 2, // << version 2 is for "Multi-container Docker running on 64bit Amazon Linux" platform
  "containerDefinitions": [
    {
      "name": "nginx",
      "essential": true,
      "image": "nginx:stable",
      "memoryReservation": 256,
      "mountPoints": [
        {
          "sourceVolume": "nginx",
          "containerPath": "/etc/nginx/"
        }
      ],
      "portMappings": [
        {
          "containerPort": 80,
          "hostPort": 80
        },
        {
          "containerPort": 443,
          "hostPort": 443
        }
      ],
      "links": [
        "flask"
      ]
    },
    {
      "name": "flask",
      "essential": true,
      "memoryReservation": 3600,
      "image": "<aws-account-id>.dkr.ecr.<region>.amazonaws.com/flask:0.1", // << local image pushed to AWS ECR
      "user": "flask",
      "command": [
        "./runApp.sh"
      ],
      "mountPoints": [
        {
          "sourceVolume": "flask",
          "containerPath": "backend"
        }
      ]
    }
  ],
  "volumes": [ // << "/var/app/current" the host path when source is bundled
    {
      "name": "nginx",
      "host": {
        "sourcePath": "/var/app/current/config/nginx/"
      }
    },
    {
      "name": "flask",
      "host": {
        "sourcePath": "/var/app/current/backend/"
      }
    }
  ]
}

Steps

  • Tag and push the local Docker image to the AWS ECR:
docker tag "${local_image}" "${remote_image}" # << tag the local image as remote name
aws ecr get-login-password --region "${ecr_region}" | \
  docker login --username AWS --password-stdin "${remote_image}" # << login to the AWS
docker push "${remote_image}" # << push the image
  • Deploy the application via:
eb deploy <app>

This command will deploy everything in the git repository except for the files defined in the .ebignore.

The commands are not checked into git (like not yet committed changes) will also be ignored.


  1. https://aws.amazon.com/about-aws/whats-new/2020/10/aws-elastic-beanstalk-support-running-multi-container-applications-al2-based-docker-platform/
  2. https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/docker-multicontainer-migration.html
  3. Multicontainer Docker configuration. AWS Elastic Beanstalk Developer Guide https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_docker_v2config.html