portainer: Creating a stack with a cifs volume in portainer does not keep options

Bug description Trying to create a stack containing a CIFS volume does not work within the portainer stack templates. When trying to run the template / docker-compose.yml file, from the command line (docker-compose up) it works. However the exact same file does not work using the stack interface. The volume driver options are not taken into account.

Expected behavior Expect the driver options to be taken into account

Steps to reproduce the issue:

  1. Go to ‘Stacks’
  2. Click on ‘Add Stack’
  3. Select ‘Web editor’
  4. create a template like following:
---
version: '2.4'
services:
  emby:
    image: emby/embyserver:latest
    container_name: embyserver
    # runtime: nvidia # Expose NVIDIA GPUs
    network_mode: host # Enable DLNA and Wake-on-Lan
    environment:
      - UID=1000
      - GID=1000
    volumes:
      - /tmp/emby:/config
      - lacie-media:/mnt/data # Media directory
    ports:
      - 8096:8096 # HTTP port
      - 8920:8920 # HTTPS port
    restart: unless-stopped

volumes:
  lacie-media:
    driver: local
    driver_opts:
      type: "cifs"
      device: "//192.168.68.254/media"
      o: "username=pi,password=password,vers=2.1,uid=1000,gid=1000"
  1. Deploy the stack.

Once deployed, the “lacie-media” volume does not have the options in portainer. ie. it does not work and connect to cifs. Where-as when running the following file as a docker-compose.yml file, using docker-compose up, it works.

Technical details:

  • Portainer version: 2.1.1
  • Docker version (managed by Portainer): Docker version 20.10.3, build 48d30b5
  • Platform (windows/linux): linux

About this issue

Most upvoted comments

Manually adding a CIFS volume via the Portainer Web UI does work. There is 1 missing piece in the options : addr=<server>

You can test this by creating a volume using the pre-defined CIFS options, then look at the volume details on the host under /var/lib/docker/volumes/<volume_name>/opts.json

{
"MountType":"cifs"
"MountOpts":"addr=<server>,username=<username>,password=<password>,vers=3.0"
"MountDevice":"//<server>/<share>"
"Quota":{"Size":0}
}

You need to add the server both as addr and as part of the share name!

The following works perfectly allowing read and write with mapped UID and GID :

Driver

Local

Driver options

type : cifs o : addr=<server>,username=<username>,password=<password>,uid=<uid>,gid=<gid>,vers=3.0 device : //<server>/<share>


Screenshot from 2023-04-02 02-20-02

image