本节我们将创建三个Task Defination
(Web, Cats, Dogs)
Task Defination
使用JSON格式定义了如何启动一个docker容器。里面包括了以下信息:
进入Task definations
页面,创建一个新的Task Defination:
命名为webdef
, Launch Type选择EC2;网络模式选择bridge类型,设置CPU和内存大小:
在Container部署,使用第一节创建完成后的web应用的ECR地址,其他保持默认:
最后点击创建
上面创建的Task Defination
是通过控制台操作的,这里我们使用JSON的方式,来避免重复的手工操作:
JSON定义如下,替换image
, awslogs-region
, account id
变量
{:
"requiresCompatibilities": [
"EC2"
],
"family": "catsdef",
"containerDefinitions": [
{
"name": "cats",
"image": "<YOUR CATS ECR IMAGE URI>",
"portMappings": [
{
"name": "cats-80-tcp",
"containerPort": 80,
"hostPort": 0,
"protocol": "tcp",
"appProtocol": "http"
}
],
"essential": true,
"environment": [],
"environmentFiles": [],
"mountPoints": [],
"volumesFrom": [],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-create-group": "true",
"awslogs-group": "/ecs/catsdef",
"awslogs-region": "<YOUR REGION>",
"awslogs-stream-prefix": "ecs"
}
}
}
],
"volumes": [],
"networkMode": "bridge",
"memory": "1024",
"cpu": "512",
"runtimePlatform": {
"cpuArchitecture": "X86_64",
"operatingSystemFamily": "LINUX"
},
"executionRoleArn": "arn:aws:iam::<YOUR ACCOUNT ID>:role/ecsTaskExecutionRole"
}
通过JSON创建Dogs Task Defination
,同样替换image
, awslogs-region
, account id
变量:
{
"requiresCompatibilities": [
"FARGATE"
],
"family": "dogsdef",
"containerDefinitions": [
{
"name": "dogs",
"image": "<YOUR DOGS ECR IMAGE URI>",
"portMappings": [
{
"name": "dogs-80-tcp",
"containerPort": 80,
"hostPort": 80,
"protocol": "tcp",
"appProtocol": "http"
}
],
"essential": true,
"environment": [],
"environmentFiles": [],
"mountPoints": [],
"volumesFrom": [],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-create-group": "true",
"awslogs-group": "/ecs/dogsdef",
"awslogs-region": "<YOUR REGION>",
"awslogs-stream-prefix": "ecs"
}
}
}
],
"volumes": [],
"networkMode": "awsvpc",
"memory": "1024",
"cpu": "512",
"runtimePlatform": {
"cpuArchitecture": "X86_64",
"operatingSystemFamily": "LINUX"
},
"executionRoleArn": "arn:aws:iam::<YOUR ACCOUNT ID>:role/ecsTaskExecutionRole"
}
注意Dogs Task Defination使用的是Fargate
,而前面两个Defination使用的是EC2