将 NFS docker 卷中的单个文件挂载到容器中 [英] Mounting a single file from an NFS docker volume into a container

查看:43
本文介绍了将 NFS docker 卷中的单个文件挂载到容器中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

示例(为简洁起见省略了许多选项):

Example (many options omitted for brevity):

version: "3"
volumes:
  traefik:
    driver: local
    driver_opts:
      type: nfs
      o: "addr=192.168.1.100,soft,rw,nfsvers=4,async"
      device: ":/volume/docker/traefik"
services:
  traefik:
    volumes:
      - traefik/traefik.toml:/traefik.toml

这个错误是因为没有名为 traefik/traefik.toml 的卷,这意味着卷名必须是文件的完整路径(即你不能在卷名)?

This errors out as there is no volume with the name traefik/traefik.toml meaning that the volume name must be the full path to the file (i.e. you can't append a path to the volume name)?

尝试设置 device: ":/volume/docker/traefik/traefik.toml" 只会返回 not a directory 错误.

Trying to set device: ":/volume/docker/traefik/traefik.toml" just returns a not a directory error.

有没有办法将单个文件挂载到容器中?

Is there a way to take a single file and mount it into a container?

推荐答案

不能在命名卷中挂载文件或子目录,源是命名卷或主机路径.NFS 本身以及您在 Linux 中挂载的大多数文件系统都要求您挂载整个文件系统,而不是单个文件,当您进入 inode 级别时,这通常是一件非常好的事情.

You cannot mount a file or sub-directory within a named volume, the source is either the named volume or a host path. NFS itself, along with most filesystems you'd mount in Linux, require you to mount an entire filesystem, not a single file, and when you get down to the inode level, this is often a really good thing.

我能想到的剩余选项是将整个目录挂载到容器内的其他位置,并符号链接到您想要的文件.或者通过 NFS 将目录挂载到主机上,然后对特定文件进行主机挂载(绑定挂载).

The options remaining that I can think of are to mount the entire directory somewhere else inside your container, and symlink to the file you want. Or to NFS mount the directory to the host and do a host mount (bind mount) to a specific file.

但是,考虑到您提供的示例,使用 docker 配置将是我理想的解决方案,完全删除 NFS 挂载,并获取文件的只读副本,该副本会自动分发到运行容器的任何节点.

However considering the example you presented, using a docker config would be my ideal solution, removing the NFS mount entirely, and getting a read only copy of the file that's automatically distributed to whichever node is running the container.

关于配置的更多细节:https://docs.docker.com/engine/swarm/configs/

这篇关于将 NFS docker 卷中的单个文件挂载到容器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆