Docker compose: mount samba volume

Hi All, i’m try to create a docker-compose file that mount external volumes with samba. I have searched more documents through google but, unfortunately, i don’t have find none.

In particular when i specify params, during execution i receive error:

version: "3.8"

services:
  web:
    build:
      dockerfile: ./Dockerfile
    ports:
      - "80:80"
    environment:
      - FlexDebug=on
    volumes:
      - cifs_mount:/root/data/

volumes:
    cifs_mount:
      driver: local
      driver_opts:
        type: cifs
        device: //server.name/dir
        o: username=xxxx,password=yyyy

Error response from daemon: error while mounting volume '/var/lib/docker/volumes/formazionephp7_cifs_mount/_data': failed to mount local volume: mount //server.name/dir:/var/lib/docker/volumes/formazionephp7_cifs_mount/_data, flags: 0x1, data: username=xxxx,password=yyyy: invalid argument

everywhere it seems function but not for me.

Can help me?

Thanks a lot.

I declared my cifs shares like this in the past:

volumes: 
  cifs-volume:
    driver_opts:
      type: cifs 
      o: username=youruser,password=yourpassword,uid=1021,gid=100,vers=3.0
      device: //192.168.x.y/share/subfolder

The permissions of your cifs user will be mapped against the uid and gid on your docker host and will have the same uid/gid inside the container.

I don’t recall the reason, but I eventually replaced all my cifs shares with nfsv4 shares.

It’s a problem of parameters not of permission.

You shared a configuration that looks like my configuration, except mine has additional optional parameters. Mine worked like this when I was still using cifs shares.

Anyhow. Please feel free to ignore my post

A problem can be anything until you find out what it is. Error messages can be misleading and one issue can cause an other.

Not to mention that @meyay also added a version number which is indeed can be important depending on what your server version is. Imagine that the server has an older version which didn’t support an argument so you get “invalid argument”. Or for some reason without uid and gid the client doesn’t have permission to use an argument (okay, I didn’t have better example and it was a bad example, but I hope you got the idea.)

One more thing can be important. Your operating system and Docker installation. Does your Docker run on a Linux host directly or in Docker Desktop (for Windows, for Linux, for macOS)?

I have never tried cifs in Docker Desktop and I may be wrong, but if the virtual machine of Docker Desktop doesn’t have cifs utils, you probably can’t mount cifs filesystem.

Hi Rimele,
it’s true. Yesterday i have try with another approach. I have create volume, before, and mount it’s after:

docker volume create --driver local --opt type=cifs --opt device=//server.name/dir --opt o=username=xxx,password=yyy,uid=1025,gid=100,vers=4.0 --opt o=bind web_data

and not receive anithing error.

After i have try to mount mi volume with compose but receive an error:

service "web" refers to undefined volume web_data: invalid compose project

I have try to add “project name before” but another error:

service "web" refers to undefined volume formazionephp7_web_data: invalid compose project

I’ll try to do more research; it’s a bit unnerving not to understand.

Thanks everyone for the help.

A volume needs to be defined in the top level volumes section, regardless whether it is created within the compose file or refers to an external (=not managed by this compose file) volume.

You compose file from the first post would change to something like this;

version: "3.8"

services:
  web:
    build:
      dockerfile: ./Dockerfile
    ports:
      - "80:80"
    environment:
      - FlexDebug=on
    volumes:
      - data:/root/data/

volumes:
  data:
    external:
      name: web_data

I have an error:

time="2022-12-04T10:49:46+01:00" level=warning msg="volume data: volume.external.name is deprecated in favor of volume.name"

i think that level “external” is deprecate.

And if i try this

volumes:
  data:
    name: web_data

i receive this error:

service “web” refers to undefined volume web_data: invalid compose project

Right, I missed that part when I looked it up in the compose specification the other day.
volume.external.name indeed is marked as deprecated, and the warning you get confirms it.

try:

volumes:
  data:
    name: web_data
    external: true

Update: I missed it, because I look at the current compose specification which does not mention it. It is the old compose file v3 reference mentions it though.

Thank you for your help.
Is very strange:

version: "3.8"

services:
  web:
    build:
      dockerfile: ./Dockerfile
    ports:
      - "80:80"
    environment:
      - FlexDebug=on
    volumes:
      - web_data:/var/www/example

volumes:
  data:
    name: web_data
    external: true

service “web” refers to undefined volume web_data: invalid compose project

You declared the volume with the name data. As such the volume needs to be addressed with its name data and not the external name.

    volumes:
      - data:/var/www/example

The compose file I shared yesterday should have worked as well. It just raised a deprecation warning, which does not prevent the configuration to work. Though, when at one point it gets finally removed from docker compose, this would have been an error that stops the compose project from starting.

Ok @meyay , you are very very Kind and i’m an idiot (i need to read the documentation better).
@rimelek I’m sorry because, actually, the problem, apparently, is in the connection or in the username/password but the error is always “wrong parameters”.

I have create, in another server, a new samba connection and now function with this configuration:

version: "3.8"

services:
  web:
    build:
      dockerfile: ./Dockerfile
    ports:
      - "80:80"
    environment:
      - FlexDebug=on
    volumes:
      - data:/var/www/example

volumes:
  data:
    driver: local
    driver_opts:
      type: cifs
      device: "//192.168.1.17/share"
      o: "username=XXX,password=YYY,uid=1000,gid=1000"

I thank you again very much for the time you have dedicated to me; very kind.

1 Like

One more thing: volumes once created are immutable. Any change in the compose file afterwards will not apply, unless the volume is manually removed and docker compose re-creates it with the new settings.

Seems this was one of your problems.

Fun fact: the same is true for networks.

Thanks a lot for your support.

un’altra cosa per il futuro: nella mia prima versione ho inserito //server.name ma, sfortunatamente, sembra accettare solo ip //192.168.1.22 (per esempio).

Translated by @rimelek using Google Translate:

one more thing for the future: in my first version I put //server.name but, unfortunately, it seems to accept only ip //192.168.1.22 (for example).

1 Like

Since you could write your previous posts in English, I guess you accidentally replied in your native language so I translated it for you :slight_smile: Please, always try to write in English so everyone can understand it without translating and search for the post.

Sorry,
i have lost original translation and accidentally i have copied my origin text.