Docker Community Forums

Share and learn in the Docker community.

How i can mount volume with only file for docker swarm?

i need some help to mount volume just only file.

i have tested methods nfs with docker-netshare but it only works for folders.

my compose file with mount file, but does not work:

version: "3.7"

services:
  web:
    image: nginx
    ports:
      - 80:80
    volumes:
      - nginx.vol:/usr/share/nginx/html/index.html
    deploy:
      placement:
        constraints: [node.role == manager]

volumes:
  nginx.vol:
    driver: nfs
    driver_opts:
      share: 192.168.1.13:/nginx_web/index.html

when i run command to mount a file i got a error:

docker run -i -t --volume-driver=nfs -v 192.168.1.13/config/traefik.toml:/root/test.toml alpine /bin/sh
docker: Error response from daemon: error while mounting volume '': VolumeDriver.Mount: exit status 32

anyway tks for your help :slight_smile:

Swarm doesn’t allow single file bindings.

Though, how about using a config or secret? Both can use a file as input. Both can be either pre-created from the cli or created within a docker-compose.yml.