【问题标题】:Uploading file to ECS task上传文件到 ECS 任务
【发布时间】:2022-10-04 22:24:29
【问题描述】:

在通过 Terraform 创建 ECS 任务时,我正在尝试上传一个简单的 .yml 文件,这里是代码 ./main.tf

resource "aws_ecs_task_definition" "grafana" {
  family                   = "grafana"
  cpu                      = "256"
  memory                   = "512"
  network_mode             = "awsvpc"
  requires_compatibilities = ["FARGATE"]
  container_definitions = jsonencode([
    {
      name  = "grafana"
      image = "grafana/grafana:latest"
      portMappings = [
        {
          containerPort = 3000,
          hostPort      = 3000,
          protocol      = "tcp"
        }
      ]
    }
  ])
}

如何将./datasource.yml(位于我的主机上)添加到任务定义中的容器中,以便在任务运行时可以使用它?我不确定是否可以使用volume { }

【问题讨论】:

  • 为此,您可能需要一个 EFS 卷。

标签: docker terraform containers amazon-ecs


【解决方案1】:

我不确定是否可以使用volume {}?

事实上,您可以查看文档https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_task_definition#example-usage

volume {
  name      = "grafana-volume"
  host_path = "./datasource.yml"
}

【讨论】:

  • 给:ClientException: Fargate compatible task definitions do not support sourcePath
【解决方案2】:

我认为您在这里有两种选择:

  • 重建 docker 镜像,包括您修改后的 datasource.yaml。

COPY datasource.yaml /usr/share/grafana/conf/provisioning/datasource.yaml

或者

  • 挂载一个卷,您可以轻松地以编程方式挂载和推送文件(EFS 执行此操作有点复杂)
mount_points = [ {
      sourceVolume  = "grafana"
      containerPath = "/var/lib/grafana/conf/provisioning"
      readOnly      = false
    }
  ]
  volumes = [
    {    
     name      = "grafana"
     host_path = "/ecs/grafana-provisioning"}
  ]

【讨论】:

    猜你喜欢
    • 2020-09-05
    • 2020-01-01
    • 2023-01-10
    • 2019-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多