Search code examples
dockeramazon-ecsamazon-efs

Sharing files with ECS and EFS


Could you help me, please?

I'm trying to configure an ECS cluster to share files using EFS but I'm facing the following issue:

level=info time=2020-03-02T17:30:27Z msg="TaskHandler: Sending task change: TaskChange: 
[arn:aws:ecs:us-east-1:959242800104:task/74086a36-c405-4248-8475-3234b011bee8 -> STOPPED, Known 
Sent: NONE, PullStartedAt: 2020-03-02 17:30:27.661062367 +0000 UTC m=+3131.201879282, 
PullStoppedAt: 2020-03-02 17:30:27.744492758 +0000 UTC m=+3131.285309673, ExecutionStoppedAt: 
2020-03-02 17:30:27.913073824 +0000 UTC m=+3131.453890739, 
arn:aws:ecs:us-east-1:959242800104:task/74086a36-c405-4248-8475-3234b011bee8 redmine -> STOPPED, Reason 
CannotCreateContainerError: Error response from daemon: failed to mount local volume: mount 
:/mnt/efs/redmine:/var/lib/docker/volumes/ecs-redmine-22-attachments-cee2f0e7e0ebc5f55000/_data,
 data: addr=10.0.0.127,nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport: 
no such file or directory, Known Sent: NONE] sent: false" module=task_handler_types.go

If I only declare a volume inside my ECS task, the container started normally but if I try to map the outside volume with the container folder the issue happens.

I followed this tutorial: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_efs.html and it seems the problem isn't in security groups but the container itself.

I'm using the alpine version of Redmine.

Follow the config snippets:


  ...
  "mountPoints": [
        {
          "readOnly": null,
          "containerPath": "/usr/src/redmine/files",
          "sourceVolume": "attachments"
        }
      ],

  ...

  "volumes": [
    {
      "efsVolumeConfiguration": {
        "fileSystemId": "fs-xxxxx",
        "rootDirectory": "/mnt/efs/redmine"
      },
      "name": "attachments",
      "host": null,
      "dockerVolumeConfiguration": null
    }
  ],

Thanks in advance.


Solution

  • I followed those links in order to solve my problem. I thought that EFS is not ready to use in ECS.

    I had to map EFS inside EC2 and after that I had access from docker container.

    https://gist.github.com/duluca/ebcf98923f733a1fdb6682f111b1a832#update-your-cloud-formation-template

    https://xiaoyunyang.github.io/post/a-complete-guide-to-deploying-your-web-app-to-amazon-web-service/#set-up-efs-with-your-containers