padmanabh pande
padmanabh pande

Reputation: 427

How to mount EFS inside a docker container?

I am trying to mount EFS inside a docker container running on EC2 server. EFS mount in EC2 is working fine with,

sudo mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport <efs-address>:/ efs

But when tried in docker container, it is giving error 'mount.nfs4: Operation not permitted'. Please let me know how to achieve this.

Upvotes: 8

Views: 22442

Answers (3)

PillFall
PillFall

Reputation: 164

If you are using Amazon Linux (ECS Optimized), or have installed the Amazon ECS Volume Plugin you can do the same as @masseyb and @yellowsoar with:

docker volume create efs \
    --driver amazon-ecs-volume-plugin \
    # example "fs-1234:/" or "fs-1234:/html" to bind an inner folder
    --opt device=fs-arn:/ \
    --opt o= \
    --opt type=efs

or within a Docker Compose:

volumes:
  efs:
    driver: amazon-ecs-volume-plugin
    driver_opts:
      device: "fs-arn:/" # example "fs-1234:/" or "fs-1234:/html" to bind an inner folder
      o: ""
      type: efs

Upvotes: 0

yellowsoar
yellowsoar

Reputation: 73

For docker-compose file:

💡Please replace aws_efs_host to your EFS DNS name.

volumes:
  volume_name:
    driver: local
    driver_opts:
      type: nfs
      o: addr=aws_efs_host,rw,nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport
      device: ":/"

References

Upvotes: 1

masseyb
masseyb

Reputation: 4132

You can create a docker volume using EFS:

docker volume create \
    --driver local \
    --opt type=nfs \
    --opt o=addr=10.0.0.50,rw,nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 \
    --opt device=:/ efs 

Then mount the volume docker run --rm -it -v efs:/mnt ubuntu:18.04.

Upvotes: 22

Related Questions