Finally, AWS released the ECS support for Docker volume drivers and volume plugins. You can now use volume plugins like Rexray or Portworx to automatically mount EBS or EFS volumes. But if you just want to use an EFS volume, there’s an easier way.

Mount EFS volumes by using Docker’s local volume driver

First, create the EFS volume and open the settings. It shows you a link called “Amazon EC2 mount instructions”, which gives you all the information you need to mount the volume on an EC2 instance.

EFS mount instructions

In the TaskDefinition, you can now add the new dockerVolumeConfiguration and use Docker’s built-in local driver. This volume driver accepts options similar to the Linux mount command.

You’ve to add “type”, “device” and “o” as driver options. The value of type is just “nfs”. The device option gets the EFS mount point. And the o option can be copied from the EFS instruction but you’ve to add “addr” with the DNS name of the EFS volume as well.

Here is how it should look at the end:

{
  "volumes": [
    {
      "name": "jenkins_home",
      "host": null,
      "dockerVolumeConfiguration": {
        "autoprovision": null,
        "labels": null,
        "scope": "task",
        "driver": "local",
        "driverOpts": {
          "type": "nfs",
          "device": "fs-1234abcd.efs.eu-west-1.amazonaws.com:/",
          "o": "addr=fs-1234abcd.efs.eu-west-1.amazonaws.com,nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2"
        }
      }
    }
  ]
}