我们可以在 AWS ECS docker 容器上安装 EFS 吗?

Can we mount EFS on AWS ECS docker container?

我有一个 ECS 实例,我的 docker 个容器是 运行。我想将 EFS 安装在 docker 容器上,即 运行 在 ECS 上。那怎么可能呢?

我可以在 ECS 实例上安装 EFS,但不能在 ECS 上的 运行 容器上安装 EFS。

EFS 具有直接连接并且能够从 docker.

在 2049 端口上远程登录它

mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 X.X.X.X:/ /efs

错误是:- mount.nfs4:不允许操作

它应该是你的任务定义的一部分,你需要在任务定义中添加卷,然后在源卷选项中引用它,这里有一个来自 AWS 的教程。

https://aws.amazon.com/blogs/compute/using-amazon-efs-to-persist-data-from-amazon-ecs-containers/

  "volumes": [
    {
      "name": "efs",
      "host": {
        "sourcePath": "/mnt/efs/mysql"
      }
    }
  ]

更新; 2020 年 1 月 17 日 - 预览 ECS/EFS 支持

2020 年 1 月 17 日 AWS announced an preview for ECS support for EFS. It is important to note that this is currently a preview release; see information on what that means in the configuration documentation.

您可以简单地定义新的 EFSVolumeConfiguration 对象,而不是定义卷及其所有连接参数。

"EFSVolumeConfiguration": {
  "fileSystemId": "fs-xxxxxx",
  "rootDirectory": "/mnt/volume/path"
}

原答案

截至 2018 年 8 月,有了 docker 批量支持,您现在可以 mount NFS shares directly into an ECS container

当前可用的文档没有详细说明如何通过 docker 卷将 EFS 与 ECS 一起使用,但是这是可能的。

配置 docker 卷

首先,在您的任务配置中包含一个类似于以下内容的 volumes 部分:

"volumes": [
   {
     "name": "efs",
     "host": null,
     "dockerVolumeConfiguration": {
       "autoprovision": null,
       "labels": null,
       "scope": "task",
       "driver": "local",
       "driverOpts": {
         "type": "nfs",
         "device": ":/",
         "o": "addr=<fs-id>.efs.us-east-1.amazonaws.com,nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport"
       }
     }
   }
]

确保更新 o 选项中的 addr 参数以匹配您的 EFS 文件系统的 DNS 名称。

然后,将此卷包含在您的一个容器定义的装载中。有关语法的更多信息,请参阅 Docker Volumes

"containerDefinitions": [
    {
        "mountPoints": [
            {
                "sourceVolume": "efs",
                "containerPath": "/path/to/mount_volume",
                "readOnly": false
            }
        ]
    }
]

用于 NFS 连接的配置选项是 AWS 在撰写本文时为 Mounting EFS filesystems 推荐的配置选项。