dockerdocker-composenfsdocker-volumenfsclient

Connection timed out when mount NFS volume in docker-compose


I have the NFS server setup and the firewall is opened for ports 111 and 2049. and I have an NFS client and also configured for ports 111 and 2049.

The connection between the servers is working fine for the above ports

when I mount manually from the NFS client it mounted successfully.

however, I want to create NFS volume in my docker-compose file to mount directly to the NFS server. but I'm receiving a connection timed out message

ERROR: for web  Cannot create container for service web: failed to mount local volume: 
mount :/root/app/django-static:/var/lib/docker/volumes/django-static/_data, data:
addr=x.x.x.x: connection timed out

Here is my docker-compose file:

version: "3.2"
services:
  proxy:
    image: nginx-1-14:0.1
    depends_on:
      - web
    restart: always
    ports:
      - "80:80"
    volumes:
      - nginx-config:/etc/nginx
      - nginx-logs:/var/log/nginx
      - django-static:/code/static
      - django-media:/code/media

  web:
    image: django-app-v1
    restart: always
    ports:
      - "8000:8000"
    volumes:
      - django-static:/code/static
      - django-media:/code/media
    environment:
      - "DEBUG_MODE=False"
      - "DJANGO_SECRET_KEY="
      - "DB_HOST=x.x.x.x”
      - "DB_PORT=5432"
      - "DB_NAME=db"
      - "DB_USERNAME=user"
      - "DB_PASSWORD=password"

volumes:
  nginx-config:
  nginx-logs:
  django-static:
   driver_opts:
     type: "nfs"
     o: "addr=<NFS_IP>,rw"
     device: ":/root/app/django-static"
  django-media:
   driver_opts:
     type: "nfs"
     o: "addr=<NFS_IP>,rw"
     device: ":/root/app/django-media"

here is my /etc/exports in NFS server:

/root/app/django-media   <NFS_client_IP>(rw,sync,no_root_squash)
/root/app/django-static           <NFS_client_IP>(rw,sync,no_root_squash)

I followed this article to setup NFS

So, NFS configured correctly between server and client but the issue in docker as it can't access the NFS server

does it need a specific port or other permissions in /etc/exports file?

Thank you!


Solution

  • For anyone having the same issue

    it worked after I use NFS4 in volume creation in docker-compose

    volumes:
     django-media:
       driver_opts:
         type: "nfs"
         o: "nfsvers=4,addr=<NFS_IP>”
         device: ":/root/app/django-media"
      django-static:
       driver_opts:
         type: "nfs"
         o: "nfsvers=4,addr=<NFS_IP>"
         device: ":/root/app/django-static"