Amazon ECS
AWS Fargate 用户指南 (API 版本 2014-11-13)
AWS 文档中描述的 AWS 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 AWS 服务入门

创建任务定义

您必须先创建任务定义,然后才能在 Amazon ECS 上运行 Docker 容器。您可以在任务定义中定义多个容器和数据卷。有关在任务定义中可用参数的更多信息,请参阅 任务定义参数

创建新的任务定义

  1. https://console.amazonaws.cn/ecs/ 上打开 Amazon ECS 控制台。

  2. 在导航窗格中,依次选择 Task Definitions (任务定义)Create new Task Definition (创建新任务定义)

  3. Select launch type compatibilities (选择启动类型兼容性) 页面上,依次选择 FARGATENext step (下一步)

    注意

    Fargate 启动类型与 Windows 容器不兼容。

  4. (Optional) If you have a JSON representation of your task definition, complete the following steps:

    1. On the Configure task and container definitions page, scroll to the bottom of the page and choose Configure via JSON.

    2. Paste your task definition JSON into the text area and choose Save.

    3. Verify your information and choose Create.

    Scroll to the bottom of the page and choose Configure via JSON.

  5. For Task Definition Name, type a name for your task definition. 最多能包含 255 个字母 (大写和小写字母)、数字、连字符和下划线。

  6. For Task execution IAM role, either select your task execution role or choose Create new role so that the console can create one for you. For more information, seeAmazon ECS 任务执行 IAM 角色.

  7. For Task size, choose a value for Task memory (GB) and Task CPU (vCPU). The table below shows the valid combinations.

    CPU value Memory value
    256 (.25 vCPU) 512 MB, 1 GB, 2 GB
    512 (.5 vCPU) 1 GB, 2 GB, 3 GB, 4 GB
    1024 (1 vCPU) 2 GB, 3 GB, 4 GB, 5 GB, 6 GB, 7 GB, 8 GB
    2048 (2 vCPU) Between 4 GB and 16 GB in 1 GB increments
    4096 (4 vCPU) Between 8 GB and 30 GB in 1 GB increments
  8. For each container in your task definition, complete the following steps:

    1. Choose Add container.

    2. Fill out each required field and any optional fields to use in your container definitions. More container definition parameters are available in the Advanced container configuration menu. For more information, see 任务定义参数.

    3. Choose Add to add your container to the task definition.

  9. (Optional) To define data volumes for your task, choose Add volume. For more information, see 在任务中使用数据卷.

    1. For Name, type a name for your volume. 最多能包含 255 个字母 (大写和小写字母)、数字、连字符和下划线。

  10. In the Tags section, specify the key and value for each tag to associate with the task definition. For more information, see Tagging Your Amazon ECS Resources.

  11. Choose Create.

任务定义模板

空任务定义模板如下所示。您可以使用此模板创建任务定义,这些任务定义随后可粘贴到控制台 JSON 输入区域或保存到文件并与 AWS CLI --cli-input-json 选项结合使用。有关更多信息,请参阅任务定义参数

{ "family": "", "taskRoleArn": "", "executionRoleArn": "", "networkMode": "host", "containerDefinitions": [ { "name": "", "image": "", "repositoryCredentials": { "credentialsParameter": "" }, "cpu": 0, "memory": 0, "memoryReservation": 0, "links": [ "" ], "portMappings": [ { "containerPort": 0, "hostPort": 0, "protocol": "tcp" } ], "essential": true, "entryPoint": [ "" ], "command": [ "" ], "environment": [ { "name": "", "value": "" } ], "mountPoints": [ { "sourceVolume": "", "containerPath": "", "readOnly": true } ], "volumesFrom": [ { "sourceContainer": "", "readOnly": true } ], "linuxParameters": { "capabilities": { "add": [ "" ], "drop": [ "" ] }, "devices": [ { "hostPath": "", "containerPath": "", "permissions": [ "mknod" ] } ], "initProcessEnabled": true, "sharedMemorySize": 0, "tmpfs": [ { "containerPath": "", "size": 0, "mountOptions": [ "" ] } ] }, "inferenceDevices": [ "" ], "secrets": [ { "name": "", "valueFrom": "" } ], "hostname": "", "user": "", "workingDirectory": "", "disableNetworking": true, "privileged": true, "readonlyRootFilesystem": true, "dnsServers": [ "" ], "dnsSearchDomains": [ "" ], "extraHosts": [ { "hostname": "", "ipAddress": "" } ], "dockerSecurityOptions": [ "" ], "interactive": true, "pseudoTerminal": true, "dockerLabels": { "KeyName": "" }, "ulimits": [ { "name": "sigpending", "softLimit": 0, "hardLimit": 0 } ], "logConfiguration": { "logDriver": "awslogs", "options": { "KeyName": "" } }, "healthCheck": { "command": [ "" ], "interval": 0, "timeout": 0, "retries": 0, "startPeriod": 0 }, "systemControls": [ { "namespace": "", "value": "" } ], "resourceRequirements": [ { "value": "", "type": "GPU" } ] } ], "volumes": [ { "name": "", "host": { "sourcePath": "" }, "dockerVolumeConfiguration": { "scope": "shared", "autoprovision": true, "driver": "", "driverOpts": { "KeyName": "" }, "labels": { "KeyName": "" } } } ], "placementConstraints": [ { "type": "memberOf", "expression": "" } ], "requiresCompatibilities": [ "FARGATE" ], "cpu": "", "memory": "", "inferenceAccelerators": [ { "deviceName": "", "deviceType": "", "devicePolicy": "" } ], "pidMode": "host", "ipcMode": "none", "tags": [ { "key": "", "value": "" } ] }

您可以使用以下 AWS CLI 命令生成此任务定义模板:

aws ecs register-task-definition --generate-cli-skeleton

本页内容: