AWS ecs 任务定义变量

AWS ecs task definition variables

是否可以在 AWS ECS 任务定义中动态设置值?例如。我有以下卷定义。

"volumes": [
    {
        "host": {
            "sourcePath": "/tmp/logs/registrations"
        },
        "name": "logs"
    }
],

我想做类似 /tmp/logs/<container_id> 的事情。

我尝试这样做是因为我有多个容器 运行 同一个应用程序。我需要为 sumologic 收集器安装每个容器日志目录。问题是如果目录没有被容器命名空间那么挂载就会发生冲突。

将日志保存到文件系统是硬性要求吗?如果没有,Sumo Logic 有一篇关于另一个选项的非常好的文章:Update On Logging With Docker.

您 运行 Sumo Logic Collector for Docker in one container and your application in another. You configure Docker to send logs from your application container to the Sumo Logic collector. This is built into Docker,因此您的应用程序不需要更改。然后,收集器容器会将这些日志发送到 Sumo Logic。

我见过这种称为 sidecar 的模式,以防您正在寻找它的其他示例。

如果不需要保存到文件系统,Cloudwatch 日志是另一种选择。

如果您使用的是 ECS 优化 AMI,它已经配置好了,您需要做的就是在容器任务定义中打开它:

http://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_awslogs.html

您还需要为每个容器配置日志组或日志流。