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

ecs-cli compose create

从复合文件创建 Amazon ECS 任务定义。

重要

建议不要对敏感信息 (如凭证数据) 使用纯文本环境变量。

重要

Some features described may only be available with the latest version of the Amazon ECS CLI. For more information about obtaining the latest version, see 安装 Amazon ECS CLI.

语法

ecs-cli compose create [--region region] [--cluster-config cluster_config_name] [--ecs-profile ecs_profile] [--aws-profile aws_profile] [--cluster cluster_name] [--launch-type launch_type] [--create-log-groups] [--help]

选项

名称 描述

--region, -r region

Specifies the AWS Region to use. Defaults to the cluster configured using the configure command.

Type: String

Required: No

--cluster-config cluster_config_name

Specifies the name of the Amazon ECS cluster configuration to use. Defaults to the cluster configuration set as the default.

Type: String

Required: No

--ecs-profile ecs_profile

Specifies the name of the Amazon ECS profile configuration to use. Defaults to the profile configured using the configure profile command.

Type: String

Required: No

--aws-profile aws_profile

Specifies the AWS profile to use. Enables you to use the AWS credentials from an existing named profile in ~/.aws/credentials.

Type: String

Required: No

--cluster, -c cluster_name

Specifies the Amazon ECS cluster name to use. Defaults to the cluster configured using the configure command.

Type: String

Required: No

--launch-type launch_type

Specifies the launch type to use. Available options are FARGATE or EC2. For more information about launch types, see Amazon ECS 启动类型.

This overrides the default launch type stored in your cluster configuration.

Type: String

Required: No

--create-log-groups

Creates the CloudWatch log groups specified in your compose files.

Required: No

--help, -h

Shows the help text for the specified command.

Required: No

示例

注册 任务定义

此示例从 hello-world 复合文件创建项目名称为 hello-world.yml 的任务定义。

ecs-cli compose --project-name hello-world --file hello-world.yml create --launch-type EC2

输出:

INFO[0000] Using ECS task definition TaskDefinition=ecscompose-hello-world:5

在没有任务联网的情况下使用 EC2 启动类型注册任务定义

此示例从 hello-world 复合文件创建项目名称为 hello-world.yml 的任务定义。为容器大小参数指定的其他 ECS 参数。

名为 hello-world.yml 的示例 Docker 复合文件:

version: '3' services: nginx: image: nginx:latest ports: - "80:80" logging: driver: awslogs options: awslogs-group: /ecs/cli/tutorial awslogs-region: us-east-1 awslogs-stream-prefix: nginx

名为 ecs-params.yml 的示例 ECS 参数文件:

version: 1 task_definition: services: nginx: cpu_shares: 256 mem_limit: 0.5GB mem_reservation: 0.5GB
ecs-cli compose --project-name hello-world --file hello-world.yml --ecs-params ecs-params.yml --region us-east-1 create --launch-type EC2

输出:

INFO[0000] Using ECS task definition TaskDefinition=ecscompose-hello-world:5

通过使用 Fargate 启动类型来注册任务定义

此示例从 hello-world 复合文件创建项目名称为 hello-world.yml 的任务定义。将为 Fargate 启动类型的任务网络配置指定其他 ECS 参数。然后,将运行任务的一个实例。

名为 hello-world.yml 的示例 Docker 复合文件:

version: '3' services: nginx: image: nginx:latest ports: - "80:80" logging: driver: awslogs options: awslogs-group: tutorial awslogs-region: us-east-1 awslogs-stream-prefix: nginx

名为 ecs-params.yml 的示例 ECS 参数文件:

version: 1 task_definition: task_execution_role: ecsTaskExecutionRole ecs_network_mode: awsvpc task_size: mem_limit: 0.5GB cpu_limit: 256 run_params: network_configuration: awsvpc_configuration: subnets: - subnet-abcd1234 - subnet-dbca4321 security_groups: - sg-abcd1234 assign_public_ip: ENABLED

命令:

ecs-cli compose --project-name hello-world --file hello-world.yml --ecs-params ecs-params.yml --region us-east-1 create --launch-type FARGATE

输出:

INFO[0000] Using ECS task definition TaskDefinition=ecscompose-hello-world:5

本页内容: