使用cloudformation在Elastic Beanstalk上启动docker multicontainer

时间:2018-06-27 06:21:19

标签: amazon-web-services docker elastic-beanstalk amazon-cloudformation

我想以可能的形式在Elastic Beanstalk(EBS)上启动docker multicontainer。

根据我对此doc的了解,我已经创建了docker映像。将其推送到ECR。然后在项目的根目录下创建一个Dockerrun.aws.json。然后在Dorckerrun.aws.json文件中链接ECR路径。 ...就是这样吗?

因此,我创建了docker映像并将其推送到ECR。我还用相应的值创建了Dockerrun.aws.json(有些不确定,例如mountPointshost.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"
        }
      ]
    }
  ]
}

但是我想知道如何在cloudformation中启动它?我的假设是我必须在cloudformation模板(yaml)中定义EBS,并在某处引用资源Dockerrun.aws.json。如果是这样,怎么办?我尚未找到用于此目的的模板(仅用于单个Docker容器)。

1 个答案:

答案 0 :(得分:0)

  

实例上的卷   从Amazon EC2容器实例中的文件夹或从源包创建卷   (部署到/ var / app / current)。使用容器定义中的mountPoints将这些卷安装到Docker容器内的路径。

Mount是ec2主机上Volume的docker挂载。

  

要安装的Amazon EC2容器实例中的卷,以及   在Docker容器文件系统上挂载它们的位置。   挂载包含应用程序内容的卷时,容器可以读取   您在源包中上传的数据。挂载日志卷以进行写入时   日志数据,Elastic Beanstalk可以从这些卷中收集日志数据。

对于云形成,您需要创建以下内容。

ElasticBeanstalk环境

X = Lambda(lambda x: K.round(x))(X_output)

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

ElasticBeanstalk应用程序

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

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

ElasticBeanstalk应用程序版本

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

   }
}

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

您可以上传应用程序代码并运行Docker。 https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-beanstalk-sourcebundle.html

ElasticBeanstalk ConfigurationTemplate

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

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