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

ecs-cli compose service create

从复合文件创建 Amazon ECS 服务。将使用预期计数 0 创建服务,因此该命令不会启动任何容器。

语法

ecs-cli compose service create [--deployment-max-percent n] [--deployment-min-healthy-percent n] [--load-balancer-name value|--target-group-arn value] [--container-name value] [--container-port value] [--role value] [--launch-type launch_type] [--health-check-grace-period integer] [--create-log-groups] [--enable-service-discovery] [--vpc value] [--private-dns-namespace value] [--private-dns-namespace-id value] [--public-dns-namespace value] [--public-dns-namespace-id value] [--sd-container-name value] [--sd-container-port value] [--dns-ttl value] [--dns-type value] [--healthcheck-custom-config-failure-threshold value] [--help]

选项

名称 描述

--deployment-max-percent

Specifies the upper limit (as a percentage of the service's desiredCount) of the number of running tasks that can be running in a service during a deployment. For more information, see maximumPercent.

Default value: 200

Required: No

--deployment-min-healthy-percent

Specifies the lower limit (as a percentage of the service's desiredCount) of the number of running tasks that must remain running and healthy in a service during a deployment. For more information, see minimumHealthyPercent.

Default value: 100

Required: No

--target-group-arn

Specifies the full Amazon Resource Name (ARN) of a previously configured Elastic Load Balancing target group to associate with your service.

Required: No

--container-name

Specifies the container name (as it appears in a container definition). This parameter is required if a load balancer or target group is specified.

Required: No, unless a load balancer or target group is specified.

--container-port

Specifies the port on the container to associate with the load balancer. This port must correspond to a containerPort in the service's task definition. This parameter is required if a load balancer or target group is specified.

Required: No, unless a load balancer or target group is specified.

--load-balancer-name

Specifies the name of a previously configured Elastic Load Balancing load balancer to associate with your service.

Required: No

--role

Specifies the name or full Amazon Resource Name (ARN) of the IAM role that allows Amazon ECS to make calls to your load balancer or target group on your behalf. This parameter is required if you are using a load balancer or target group with your service. If you specify the role parameter, you must also specify a load balancer name or target group ARN, along with a container name and container port.

Required: No, unless a load balancer or target group is specified.

--health-check-grace-period

Specifies the period of time, in seconds, that the Amazon ECS service scheduler should ignore unhealthy Elastic Load Balancing target health checks after a task has first started.

Required: No

--create-log-groups

Creates the CloudWatch log groups specified in your compose files.

Required: No

--enable-service-discovery

Specifies whether to enable service discovery for this service.

Required: No

--vpc

Specifies the VPC that will be attached to the private DNS namespace for service discovery. This parameter is required if --private-dns-namespace is specified.

Required: No

--private-dns-namespace

Specifies the name of the private DNS namespace to use with service discovery. The ECS CLI automatically creates the namespace if it does not exist. For example, if the namespace is corp, then a service named foo is reachable via DNS at foo.corp. If this parameter is used, you must also specify a VPC using the --vpc parameter.

Required: No

--private-dns-namespace-id

Specifies the ID of an existing private DNS namespace to use with service discovery. If this parameter is used, you cannot specify either --private-dns-namespace or --vpc.

Required: No

--public-dns-namespace

Specifies the name of the public DNS namespace to use with service discovery. For example, if the namespace is corp, then a service named foo is reachable via DNS at foo.corp.

Required: No

--public-dns-namespace-id

Specifies the ID of an existing public DNS namespace to use with service discovery. If this parameter is used, you cannot specify a --public-dns-namespace.

Required: No

--sd-container-name

Specifies the name of the container, which is referred to as a service in your Docker compose file. For more information, see Service configuration reference. This parameter is required if you are using SRV records.

Required: No, unless SRV DNS records are being used.

--sd-container-port

Specifies the port on the container that will be used for service discovery. This parameter is required if you are using SRV records.

Required: No, unless SRV DNS records are being used.

--dns-ttl

Specifies the amount of time, in seconds, that you want DNS resolvers to cache the settings for the DNS records used for service discovery.

Default value: 60

Required: No

--dns-type

Specifies the type of DNS record used for service discovery. Accepted values are A or SRV. If your task uses either the bridge or host network modes, then SRV records are required. If your task uses the awsvpc network mode then A records are the default.

Required: No

--healthcheck-custom-config-failure-threshold

Specifies the number of 30-second intervals that you want the service discovery service to wait after receiving an UpdateInstanceCustomHealthStatus request before it changes the health status.

Default value: 1

Required: No

--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

--help, -h

Shows the help text for the specified command.

Required: No

使用负载均衡器

您可选择借助负载均衡器运行您的服务。负载均衡器将在与服务关联的各个任务间分配流量。有关更多信息,请参阅 服务负载均衡。在创建服务后,在服务定义中指定的负载均衡器名称或目标组 ARN、容器名称和容器端口是不可变的。

注意

您必须先创建负载均衡器资源,然后才能将服务配置为使用它们。您的负载均衡器资源应与您的容器实例位于同一 VPC 中,并且应将它们配置为使用相同的子网。您还必须向容器实例安全组添加一个安全组规则,该规则允许来自负载均衡器的入站流量。有关更多信息,请参阅 创建负载均衡器

  • 要将服务配置为使用现有 Elastic Load Balancing 传统负载均衡器,您必须指定负载均衡器名称、容器名称 (显示在容器定义中) 和要从负载均衡器访问的容器端口。将此服务中的任务放在容器实例上后,容器实例将注册到在此处指定的负载均衡器。

  • 要将服务配置为使用现有 Elastic Load Balancing 应用程序负载均衡器,您必须指定负载均衡器目标组 ARN、容器名称 (显示在容器定义中) 和要从负载均衡器访问的容器端口。将此服务中的任务放在容器实例上后,容器实例和端口组合将注册为在此处指定的目标组中的目标。

The --health-check-grace-period option specifies the period of time, in seconds, that the Amazon ECS service scheduler should ignore unhealthy Elastic Load Balancing target health checks after a task has first started. This is only valid if your service is configured to use a load balancer. If your tasks take a while to start and respond to ELB health checks, you can specify a health check grace period of up to 1,800 seconds during which the ECS service scheduler ignores the Elastic Load Balancing health check status. This grace period can prevent the Amazon ECS service scheduler from marking tasks as unhealthy and stopping them before they have time to come up.

使用 Service Discovery

Amazon ECS 服务可以选择配置为使用 Amazon ECS Service Discovery。Service discovery 使用 Amazon Route 53 自动命名 API 操作来管理服务任务的 DNS 条目,使其可在 VPC 中供搜索。有关更多信息,请参阅 教程:使用 Amazon ECS CLI 创建使用Service Discovery的 Amazon ECS 服务