简体   繁体   中英

Start docker multicontainer on Elastic Beanstalk with cloudformation

I want to start docker multicontainer on Elastic Beanstalk (EBS) with couldformation.

From what I understood from this doc is that I have create docker images. Push it to ECR. Then create a Dockerrun.aws.json at the root of my project. Then link the ECR path in the Dorckerrun.aws.json file. ...and that's it?

So I created the docker images and pushed it to ECR. I also created the Dockerrun.aws.json with the corresponding values (some I'm not quite sure... eg what is the difference between mountPoints and host.sourcePath ).

{
  "AWSEBDockerrunVersion": 2,
  "volumes": [
    {
      "name": "myApplication1",
      "host": {
        "sourcePath": "/var/app/current/myApplication1"
      }
    },
    {
      "name": "myApplication2",
      "host": {
        "sourcePath": "/var/app/current/myApplication2"
      }
    },
    {
      "name": "myApplication3",
      "host": {
        "sourcePath": "/var/app/current/myApplication3"
      }
    }
  ],
  "containerDefinitions": [
    {
      "name": "myApplication1",
      "image": "123456789.dkr.ecr.eu-central-1.amazonaws.com/myDocker/myApplication1",
      "essential": true,
      "memory": 128,
      "mountPoints": [
        {
          "sourceVolume": "????",
          "containerPath": "????",
          "readOnly": true
        },
        {
          "sourceVolume": "awseb-logs-myApplication1",
          "containerPath": "/var/log/myApplication1"
        }
      ]
    },
    {
      "name": "myApplication2",
      "image": "123456789.dkr.ecr.eu-central-1.amazonaws.com/myDocker/myApplication2",
      "essential": true,
      "memory": 128,
      "portMappings": [
        {
          "hostPort": 80,
          "containerPort": 80
        }
      ],
      "links": [
        "myApplication1", "myApplication3"
      ],
      "mountPoints": [
        {
          "sourceVolume": "????",
          "containerPath": "????",
          "readOnly": true
        },
        {
          "sourceVolume": "?????",
          "containerPath": "????",
          "readOnly": true
        },
        {
          "sourceVolume": "awseb-logs-myApplication2",
          "containerPath": "/var/log/myApplication2"
        }
      ]
    },
    {
      "name": "myApplication3",
      "image": "123456789.dkr.ecr.eu-central-1.amazonaws.com/myDocker/myApplication3",
      "essential": true,
      "memory": 128,
      "mountPoints": [
        {
          "sourceVolume": "?????",
          "containerPath": "?????",
          "readOnly": true
        },
        {
          "sourceVolume": "awseb-logs-myApplication3",
          "containerPath": "/var/log/myApplication3"
        }
      ]
    }
  ]
}

But I was wondering how to start it in cloudformation? My assumption is that I have to define EBS in cloudformation template (yaml) and reference the resource Dockerrun.aws.json somewhere. If so, how? I haven't found a template for that purpose (only for single docker container).

Volumes on the instance Creates volumes from folders in the Amazon EC2 container instance, or from your source bundle (deployed to /var/app/current). Mount these volumes to paths within your Docker containers using mountPoints in the container definition.

Mount is the docker mount of the Volume on the ec2 host.

Volumes from the Amazon EC2 container instance to mount, and the location on the Docker container file system at which to mount them. When you mount volumes that contain application content, your container can read the data you upload in your source bundle. When you mount log volumes for writing log data, Elastic Beanstalk can gather log data from these volumes.

For Cloud formation you need to create the following.

ElasticBeanstalk Environment

{
   "Type" : "AWS::ElasticBeanstalk::Environment",
   "Properties" : {
      "ApplicationName" : String,
      "CNAMEPrefix" : String,
      "Description" :  String,
      "EnvironmentName" :  String,
      "OptionSettings" : [ OptionSetting, ... ],
      "PlatformArn" : String,
      "SolutionStackName" : String,
      "Tags" : [ Resource Tag, ... ],
      "TemplateName" : String,
      "Tier" : Environment Tier,
      "VersionLabel" : String
   }
}

Docker platforms https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/concepts.platforms.html#concepts.platforms.docker

ElasticBeanstalk Application

{
   "Type" : "AWS::ElasticBeanstalk::Application",
   "Properties" : {
      "ApplicationName" : String,
      "Description" : String,
      "ResourceLifecycleConfig" : ApplicationResourceLifecycleConfig

   }
}

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-beanstalk.html

ElasticBeanstalk Application Version

{
  "Type" : "AWS::ElasticBeanstalk::ApplicationVersion",
  "Properties" : {
    "ApplicationName" : String,
    "Description" : String,
    "SourceBundle" : { SourceBundle }
  }
}

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-beanstalk-version.html

You can upload your application code and the Docker run. https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-beanstalk-sourcebundle.html

ElasticBeanstalk ConfigurationTemplate

{
  AWS::ElasticBeanstalk::ConfigurationTemplate
    {
      "Type" : "AWS::ElasticBeanstalk::ConfigurationTemplate",
      "Properties" : {  
        "ApplicationName" : String,
        "Description" : String,
        "EnvironmentId" : String,
        "OptionSettings" : [ ConfigurationOptionSetting, ... ],
        "PlatformArn" : String,
        "SolutionStackName" : String,
        "SourceConfiguration" : SourceConfiguration
      } 
    }
}

https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_docker_image.html https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_docker_v2config.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM