Docker 容器访问 NFS 共享的权限被拒绝 - Docker 撰写

Permission denied to Docker container accessing NFS share - Docker Compose

我在使用 Docker Compose 将 WD MyCloud EX2 NAS 安装为 Nextcloud 和 MariaDB 容器组合的 NFS 共享时遇到问题。当我 运行 docker-compose up -d 时,这是我得到的错误:

Creating nextcloud_app_1 ... error

ERROR: for nextcloud_app_1  Cannot create container for service app: b"error while mounting volume with options: type='nfs' device=':/mnt/HD/HD_a/nextcloud' o='addr=192.168.1.73,rw': permission denied"

ERROR: for app  Cannot create container for service app: b"error while mounting volume with options: type='nfs' device=':/mnt/HD/HD_a/nextcloud' o='addr=192.168.1.73,rw': permission denied"
ERROR: Encountered errors while bringing up the project.

这里是 docker-compose.yml(所有敏感信息都替换为 <括号>:

Version: '2'

volumes:
  nextcloud:
    driver: local
    driver_opts:
      type: nfs
      o: addr=192.168.1.73,rw
      device: ":/mnt/HD/HD_a/nextcloud"
  db:

services:
  db:
    image: mariadb
    command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
    restart: always
    volumes:
      - db:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=<****>
      - MYSQL_PASSWORD=<****>
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
      - NEXTCLOUD_ADMIN_USER=<****>
      - NEXTCLOUD_ADMIN_PASSWORD=<****>

  app:
    image: nextcloud
    ports:
      - 8080:80
    links:
      - db
    volumes:
      - nextcloud:/var/www/html
    restart: always

我通过 SSHd 进入 NAS 框来检查 /etc/exports,果然,它正在使用 all_squash,所以我改变了它。

这是 NAS 盒上的 /etc/exports 文件:

    "/nfs/nextcloud" 192.168.1.73(rw,no_root_squash,sync,no_wdelay,insecure_locks,insecure,no_subtree_check,anonuid=501,anongid=1000)
    "/nfs/Public" 192.168.1.73(rw,no_root_squash,sync,no_wdelay,insecure_locks,insecure,no_subtree_check,anonuid=501,anongid=1000)

然后,我用exportfs -a

刷新了服务

没有任何变化 - docker-compose 抛出同样的错误。每次尝试构建时,我都会删除所有容器和图像并重新下载图像。

我已经阅读了类似的问题并做了我能想到的一切。我也知道这是一个容器问题,因为由于我在 /etc/fstabs 中的设置,我可以从命令行非常愉快地访问 NFS 共享。

我还应该在这里做什么?

尝试使用命令行检查 ini nextcloud 文件夹 "ls -l /var/www/html",查看可以访问它的组和用户

我通过删除 NAS 盒 /etc/exports 文件中的 anonuid=501,anongid=1000 条目修复了它,我还设法输入了错误的 IP - NAS 盒未授予对 Ubuntu 试图与之连接的计算机。

在我们的例子中,我们在本地安装 nfs 卷 docker 主机,然后将文件夹安装在容器中。

我们是 运行 oracle-linux 7,启用了 SElinux。 我们通过在 fs_mntops 块中的 /etc/fstab 内添加以下参数来修复(参见 https://man7.org/linux/man-pages/man5/fstab.5.html):

defaults,context="system_u:object_r:svirt_sandbox_file_t:s0"