在 docker-compose 中挂载 NFS 卷时连接超时

Connection timed out when mount NFS volume in docker-compose

我设置了 NFS 服务器,并为端口 111 和 2049 打开了防火墙。 我有一个 NFS 客户端并且还配置了端口 111 和 2049。

对于上述端口,服务器之间的连接工作正常

当我从 NFS 客户端手动挂载时,它成功挂载了。

但是,我想在我的 docker-compose 文件中创建 NFS 卷以直接挂载到 NFS 服务器。 但我收到连接超时消息

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

这是我的 docker-compose 文件:

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"

这是我在 NFS 服务器中的 /etc/exports:

/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

因此,NFS 在服务器和客户端之间正确配置 但是 docker 中的问题,因为它无法访问 NFS 服务器

是否需要特定端口或 /etc/exports 文件中的其他权限?

谢谢!

遇到同样问题的人

我在 docker-compose

的卷创建中使用 NFS4 后它起作用了
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"