我想使用 canformation 在 Elastic Beanstalk (EBS) 上启动 docker multicontainer。
据我了解,doc 是我已经创建了 docker 镜像。将其推至 ECR。然后在我的项目的根目录下创建一个 Dockerrun.aws.json
。然后链接 Dorckerrun.aws.json
文件中的 ECR 路径。 ...就这样?
所以我创建了 docker 镜像并将其推送到 ECR。我还使用相应的值创建了 Dockerrun.aws.json
(有些我不太确定......例如 mountPoints
和 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"
}
]
}
]
}
但是我想知道如何在cloudformation中启动它?我的假设是我必须在 cloudformation 模板 (yaml) 中定义 EBS 并在某处引用资源 Dockerrun.aws.json
。如果是这样,怎么办?我还没有找到用于此目的的模板(仅适用于单个 Docker 容器)。
最佳答案
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 是卷在 ec2 主机上的 docker 挂载。
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.
对于云形成,您需要创建以下内容。
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
}
}
ElasticBeanstalk 应用程序
{
"Type" : "AWS::ElasticBeanstalk::Application",
"Properties" : {
"ApplicationName" : String,
"Description" : String,
"ResourceLifecycleConfig" : ApplicationResourceLifecycleConfig
}
}
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-beanstalk.html
ElasticBeanstalk 应用程序版本
{
"Type" : "AWS::ElasticBeanstalk::ApplicationVersion",
"Properties" : {
"ApplicationName" : String,
"Description" : String,
"SourceBundle" : { SourceBundle }
}
}
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 配置模板
{
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
关于amazon-web-services - 使用 cloudformation 在 Elastic Beanstalk 上启动 docker 多容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51055815/