How to directly mount NFS share/volume in container using docker compose v3

后端 未结 5 1502
予麋鹿
予麋鹿 2020-12-04 07:46

I have a compose file with v3 where there are 3 services sharing/using the same volume. While using swarm mode we need to create extra containers & volumes to manage our

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-04 08:03

    My solution for AWS EFS, that works:

    1. Create EFS (don't forget to open NFS port 2049 at security group)
    2. Install nfs-common package:

      sudo apt-get install -y nfs-common

    3. Check if your efs works:

      mkdir efs-test-point
      sudo chmod go+rw efs-test-point
      sudo mount -t nfs -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport [YOUR_EFS_DNS]:/ efs-test-point
      touch efs-test-point/1.txt
      sudo umount efs-test-point/
      ls -la efs-test-point/

      directory must be empty

      sudo mount -t nfs -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport [YOUR_EFS_DNS]:/ efs-test-point

      ls -la efs-test-point/

      file 1.txt must exists

    4. Configure docker-compose.yml file:

      services:
        sidekiq:
          volumes:
            - uploads_tmp_efs:/home/application/public/uploads/tmp
        ...
      volumes:
        uploads_tmp_efs:
          driver: local
          driver_opts:
            type: nfs
            o: addr=[YOUR_EFS_DNS],nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2
            device: [YOUR_EFS_DNS]:/

提交回复
热议问题