Can we mount EFS on AWS ECS docker container?

mahendra rathod picture mahendra rathod · Feb 26, 2018 · Viewed 7.4k times · Source

I have an ECS instance on which my docker containers are running. I want to mount EFS on docker container which is running on ECS. Is it possible then how?

I am able to mount EFS on ECS instance but not on docker container which is running on ECS.

EFS is with direct connect & able to telnet it on 2049 port from docker.

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

Error is :- mount.nfs4: Operation not permitted

Answer

Luke Waite picture Luke Waite · Oct 5, 2018

Update; Jan 17 2020 - Preview ECS/EFS Support

On January 17 2020 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.

Instead of defining volumes and all of their connection parameters, you may simply define the new EFSVolumeConfiguration object.

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

Original Answer

As of August 2018, with docker volume support, you can now mount NFS shares directly into an ECS container.

The documentation which is available currently does not detail how to use EFS with ECS via docker volume, however it is possible.

Configuring the docker volume

First, include a volumes section in your task configuration similar to the following:

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

Ensure that you update the addr parameter inside the o option to match your EFS filesystem's DNS name.

Then, include this volume in a mount in one of your container definitions. For more information on the syntax, see Docker Volumes.

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

The configuration options being used for the NFS connection are the ones recommended at time of writing by AWS for Mounting EFS filesystems.