简体   繁体   English

Terraform ECS 任务定义中的多个卷 JSON

[英]Terraform multiple volumes in ECS task definition JSON

I want to add multiple volume defintions in my ECS task definition JSON like this:我想在我的 ECS 任务定义 JSON 中添加多个卷定义,如下所示:

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

This is obviously not working because json cannot have 2 keys volume with the same name.这显然不起作用,因为 json 不能有 2 个同名的键volume How to acheive this?如何实现这一目标? Please help.请帮忙。

how are you?你好吗?

I don't know exactly what you are trying to achieve, but let me try to help with a few ideas:我不确切知道您要达到的目标,但让我尝试提供一些想法:

The following will map the /data/agent3/conf to the /data/agent/conf inside your container:以下将 map 将/data/agent3/conf到容器内的/data/agent/conf中:

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

If you want to use two volumes:如果要使用两个卷:

{
    "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"
              }
        }
    ]
}

As far as I know, It's not possible to mount two volumes into the same mount point within your container.据我所知,不可能将两个卷挂载到容器内的同一个挂载点。 :) :)

But if you're trying to share data between containers/tasks between multiple hosts, Amazon EFS will be a better option.但是,如果您尝试在多个主机之间的容器/任务之间共享数据,Amazon EFS 将是一个更好的选择。

You can find more details bellow:您可以在下面找到更多详细信息:

Amazon ECS and Docker volume drivers Amazon ECS 和 Docker 卷驱动程序

Bind Mounts 绑定坐骑

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM