4

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.

padmanabh pande
  • 367
  • 2
  • 4
  • 21
  • 1
    Possible duplicate of [Mounting nfs shares inside docker container](https://stackoverflow.com/questions/39922161/mounting-nfs-shares-inside-docker-container) – David Maze Aug 29 '19 at 11:14
  • 1
    Is creating a `docker` volume and using that not an option? e.g. `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 using the volume `docker run --rm -it -v efs:/mnt ubuntu:18.04` – masseyb Aug 29 '19 at 11:24

1 Answers1

15

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.

masseyb
  • 3,745
  • 1
  • 17
  • 29
  • This works as per my requirement, but there is one catch. This needs two steps: 1. Create docker volume, 2. Run docker image. Is it possible to have a single step for this? Can I change my dockerfile somehow to do this job? – padmanabh pande Sep 03 '19 at 07:33
  • @padmanabhpande can't do anything with the `Dockerfile` itself, if using `docker-compose` then you could define the `docker volume` there and it would create the `docker volume` if it doesn't already exist when bringing up the service(s). – masseyb Oct 31 '19 at 10:29