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

查看:444
本文介绍了将单个文件从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/

More details on configs: https://docs.docker.com/engine/swarm/configs/

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

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