Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mounting a single file from an NFS docker volume into a container

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

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)?

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?

like image 600
dalanmiller Avatar asked Sep 15 '25 00:09

dalanmiller


1 Answers

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.

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.

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.

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

like image 82
BMitch Avatar answered Sep 17 '25 19:09

BMitch