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

示例任务定义

以下是一些任务定义示例,您可以使用这些示例来开始创建自己的任务定义。有关更多信息,请参阅 任务定义参数创建任务定义

主题

    例 示例:Web 服务器

    下面是用于设置 Web 服务器的示例任务定义 (使用 Fargate 启动类型):

    { "containerDefinitions": [ { "command": [ "/bin/sh -c \"echo '<html> <head> <title>Amazon ECS Sample App</title> <style>body {margin-top: 40px; background-color: #333;} </style> </head><body> <div style=color:white;text-align:center> <h1>Amazon ECS Sample App</h1> <h2>Congratulations!</h2> <p>Your application is now running on a container in Amazon ECS.</p> </div></body></html>' > /usr/local/apache2/htdocs/index.html && httpd-foreground\"" ], "entryPoint": [ "sh", "-c" ], "essential": true, "image": "httpd:2.4", "logConfiguration": { "logDriver": "awslogs", "options": { "awslogs-group" : "/ecs/fargate-task-definition", "awslogs-region": "us-east-1", "awslogs-stream-prefix": "ecs" } }, "name": "sample-fargate-app", "portMappings": [ { "containerPort": 80, "hostPort": 80, "protocol": "tcp" } ] } ], "cpu": "256", "executionRoleArn": "arn:aws:iam::012345678910:role/ecsTaskExecutionRole", "family": "fargate-task-definition", "memory": "512", "networkMode": "awsvpc", "requiresCompatibilities": [ "FARGATE" ] }

    重要

    如果您将此任务定义与负载均衡器一起使用,则需要在容器启动后立即通过容器实例上的 Web 接口完成 WordPress 安装程序安装。负载均衡器运行状况检查 ping 将预计来自服务器的 200 响应,但 WordPress 将返回 301,直到安装完成。如果未通过负载均衡器运行状况检查,则负载均衡器会取消注册该实例。

    例 示例:awslogs 日志驱动程序

    以下示例演示如何在使用 Fargate 启动类型的任务定义中使用 awslogs 日志驱动程序。nginx 容器将其日志发送到 ecs-log-streaming 区域中的 us-west-2 日志组。有关更多信息,请参阅 使用 awslogs 日志驱动程序

    { "containerDefinitions": [ { "memory": 128, "portMappings": [ { "hostPort": 80, "containerPort": 80, "protocol": "tcp" } ], "essential": true, "name": "nginx-container", "image": "nginx", "logConfiguration": { "logDriver": "awslogs", "options": { "awslogs-group": "ecs-log-streaming", "awslogs-region": "us-west-2", "awslogs-stream-prefix": "fargate-task-1" } }, "cpu": 0 } ], "networkMode": "awsvpc", "executionRoleArn": "arn:aws:iam::123456789012:role/ecsTaskExecutionRole", "memory": "2048", "cpu": "1024", "requiresCompatibilities": [ "FARGATE" ], "family": "example_task_1" }