mahendra rathod
mahendra rathod

Reputation: 1638

Can we mount EFS on AWS ECS docker container?

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

Upvotes: 9

Views: 13521

Answers (3)

RaghuCK
RaghuCK

Reputation: 125

Approach 1: When you want to mount the EFS to EC2 instance and then make all the containers to use it. Run below command to mount the EFS to the EC2 instance.

sudo mount -t efs fs-0ad7c287c2f7c27c2 /mnt/efs

Then reference it in the task-definition as sourcePath so the container can use the efs mount path as the writable layer.

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

Approach 2: When auto-scaling is enabled on ECS, it's good to attach the EFS volume directly to the ECS task/container. In task-definition mention like below so the containers will directly mount the EFS upon spawn.

"volumes": [
    {
        "name": "Tiger-Test",
        "efsVolumeConfiguration": {
        "fileSystemId": "fs-0ad7c287c2f7c27c2"
        }
    }
]

Upvotes: 0

Luke Waite
Luke Waite

Reputation: 2475

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.

Upvotes: 21

Sudharsan Sivasankaran
Sudharsan Sivasankaran

Reputation: 5897

It should part of your task definition, you need to add the volumes in the task definition and then refer it in the source volume option, here is a tutorial from 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"
      }
    }
  ]

Upvotes: 4

Related Questions