Locally mount AWS EFS using docker-compose Locally mount AWS EFS using docker-compose docker docker

Locally mount AWS EFS using docker-compose


EFS assumes nfs4, so:

version: '3.8'services:  postgres:    volumes:      postgres_data:/var/lib/postgresql/datavolumes:   postgres_data:    driver_opts:      type: "nfs4"      o: "addr=xxx.xx.xx.xx,nolock,soft,rw"      device: ":/docker/postgres_data"

Of course, the referenced nfs-export/path must exist. Swarm will not automatically create non-existing folders.

Make sure to delete any old docker volumes of this faulty kind/name manually (on all swarm nodes!) before recreating the stack:

docker volume rm $(docker volume ls -f name=postgres_data -q)

This is important to understand: Docker NFS Volumes are actually only the declaration where to find the data. It does not update when you update your docker-compose.yml, hence you must remove the volume so any new configuration will appear

see output of

docker service ps stack_postgres --no-trunc

for more information why volume couldn't be mountet

Also make sure you can mount the nfs-export via mount -t nfs4 ...

see showmount -e your.efs.ip.address