【问题标题】:Terraform multiple volumes in ECS task definition JSONECS 任务定义 JSON 中的 Terraform 多个卷
【发布时间】:2022-01-06 18:52:29
【问题描述】:

我想在我的 ECS 任务定义 JSON 中添加多个卷定义,如下所示:

[
{
    "name": "agent",
    "image": "${agent_image}",
    "essential": true,
    "environment": [
        {
            "name": "apple",
            "value": "mango"
        },
        {
            "name": "AGENT_NAME",
            "value": "AGENT3"
        }
    ],
    "volume": {
        "name"      : "/data/agent2/conf",
        "host_path" : "/data/agent2/conf"
    }
    "volume": {
        "name"      : "/data/agent3/conf",
        "host_path" : "/data/agent3/conf"
    }
    
}
]

这显然不起作用,因为 json 不能有 2 个键 volume 具有相同的名称。如何实现这一目标?请帮忙。

【问题讨论】:

  • 不知道为什么你想要 2 个同名的卷块,但是 2 个不同名称的卷块应该可以工作 & 你是否尝试了 1 个带有名称列表的卷块? “卷”:[{“名称”:“/data/agent/conf”,“host_path”:“/data/agent3/conf”},{“名称”:“/data/agent/conf”,“host_path” : "/data/agent3/conf" } ]

标签: amazon-web-services docker terraform amazon-ecs


【解决方案1】:

我不确切知道您想要实现什么,但让我尝试提供一些想法:

以下内容会将/data/agent3/conf 映射到容器内的/data/agent/conf

{
    "containerDefinitions": [
        {
            "mountPoints": [
                {
                    "containerPath": "/data/agent/conf",
                    "sourceVolume": "vol1"
                }
            ]
        }
    ],
    "volumes": [
        {
            "name": "vol1",
            "host": {
                "sourcePath": "/data/agent3/conf"
              }
        }
    ]
}

如果你想使用两个卷:

{
    "containerDefinitions": [
        {
            "mountPoints": [
                {
                    "containerPath": "/data/agent/conf",
                    "sourceVolume": "vol1"
                },
                {
                    "containerPath": "/alternate/path/to/conf",
                    "sourceVolume": "vol2"
                }
            ]
        }
    ],
    "volumes": [
        {
            "name": "vol1",
            "host": {
                "sourcePath": "/data/agent3/conf"
              }
        },
        {
            "name": "vol2",
            "host": {
                "sourcePath": "/data/agent3/conf"
              }
        }
    ]
}

据我所知,不可能将两个卷挂载到容器内的同一个挂载点。 :)

但如果您尝试在多个主机之间的容器/任务之间共享数据,Amazon EFS 将是更好的选择。

您可以在下面找到更多详细信息:

Amazon ECS and Docker volume drivers

Bind Mounts

【讨论】:

    猜你喜欢
    • 2021-09-17
    • 2021-01-19
    • 2020-01-03
    • 1970-01-01
    • 2021-11-05
    • 2019-06-08
    • 2020-03-24
    • 2021-07-26
    • 2021-12-01
    相关资源
    最近更新 更多