# Docker compose: mount samba volume

**URL:** <https://forums.docker.com/t/docker-compose-mount-samba-volume/132407>\
**Category:** Compose\
**Created:** [December 2, 2022, 5:44pm UTC](https://forums.docker.com/t/docker-compose-mount-samba-volume/132407 "2022-12-02T17:44:23Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![macjames](https://avatars.discourse-cdn.com/v4/letter/m/ed8c4c/32.png) [@macjames](https://forums.docker.com/u/macjames)\
**Post date:** [December 2, 2022, 5:44pm UTC](https://forums.docker.com/t/docker-compose-mount-samba-volume/132407/1 "2022-12-02T17:44:24Z")

</div>

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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![meyay](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/meyay/32/34000_2.png) [@meyay](https://forums.docker.com/u/meyay)\
**Post date:** [December 2, 2022, 7:24pm UTC](https://forums.docker.com/t/docker-compose-mount-samba-volume/132407/2 "2022-12-02T19:24:45Z")

</div>

I declared my cifs shares like this in the past:

```auto
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.

---

<div class="post-metadata">

**Author:** ![macjames](https://avatars.discourse-cdn.com/v4/letter/m/ed8c4c/32.png) [@macjames](https://forums.docker.com/u/macjames)\
**Post date:** [December 2, 2022, 9:36pm UTC](https://forums.docker.com/t/docker-compose-mount-samba-volume/132407/3 "2022-12-02T21:36:18Z")

</div>

It’s a problem of parameters not of permission.

---

<div class="post-metadata">

**Author:** ![meyay](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/meyay/32/34000_2.png) [@meyay](https://forums.docker.com/u/meyay)\
**Post date:** [December 2, 2022, 9:44pm UTC](https://forums.docker.com/t/docker-compose-mount-samba-volume/132407/4 "2022-12-02T21:44:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rimelek](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/rimelek/32/41602_2.png) [@rimelek](https://forums.docker.com/u/rimelek)\
**Post date:** [December 2, 2022, 11:10pm UTC](https://forums.docker.com/t/docker-compose-mount-samba-volume/132407/5 "2022-12-02T23:10:42Z")

</div>

> [@macjames](#):
>
> It’s a problem of parameters not of permission.

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.

---

<div class="post-metadata">

**Author:** ![macjames](https://avatars.discourse-cdn.com/v4/letter/m/ed8c4c/32.png) [@macjames](https://forums.docker.com/u/macjames)\
**Post date:** [December 3, 2022, 6:24am UTC](https://forums.docker.com/t/docker-compose-mount-samba-volume/132407/6 "2022-12-03T06:24:55Z")

</div>

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.

 ![image](https://global.discourse-cdn.com/docker/original/3X/9/c/9c4627a338f2c73eb6ff66cbd6fb5d930b87fe83.png)

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.

---

<div class="post-metadata">

**Author:** ![meyay](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/meyay/32/34000_2.png) [@meyay](https://forums.docker.com/u/meyay)\
**Post date:** [December 3, 2022, 10:39am UTC](https://forums.docker.com/t/docker-compose-mount-samba-volume/132407/7 "2022-12-03T10:39:23Z")

</div>

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;

```auto
version: "3.8"

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

volumes:
  data:
    external:
      name: web_data

```

---

<div class="post-metadata">

**Author:** ![macjames](https://avatars.discourse-cdn.com/v4/letter/m/ed8c4c/32.png) [@macjames](https://forums.docker.com/u/macjames)\
**Post date:** [December 4, 2022, 9:51am UTC](https://forums.docker.com/t/docker-compose-mount-samba-volume/132407/8 "2022-12-04T09:51:16Z")

</div>

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

```auto
volumes:
  data:
    name: web_data

```

i receive this error:

> service “web” refers to undefined volume web\_data: invalid compose project

---

<div class="post-metadata">

**Author:** ![meyay](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/meyay/32/34000_2.png) [@meyay](https://forums.docker.com/u/meyay)\
**Post date:** [December 4, 2022, 10:01am UTC](https://forums.docker.com/t/docker-compose-mount-samba-volume/132407/9 "2022-12-04T10:01:57Z")

</div>

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:

```auto
volumes:
  data:
    name: web_data
    external: true
```

Update: I missed it, because I look at the current [compose specification](https://docs.docker.com/compose/compose-file/#external-1) which does not mention it. It is the old [compose file v3 reference](https://docs.docker.com/compose/compose-file/compose-file-v3/#external) mentions it though.

---

<div class="post-metadata">

**Author:** ![macjames](https://avatars.discourse-cdn.com/v4/letter/m/ed8c4c/32.png) [@macjames](https://forums.docker.com/u/macjames)\
**Post date:** [December 4, 2022, 10:03am UTC](https://forums.docker.com/t/docker-compose-mount-samba-volume/132407/10 "2022-12-04T10:03:44Z")

</div>

Thank you for your help.  
Is very strange:

 ![image](https://global.discourse-cdn.com/docker/original/3X/b/b/bbefd4b525d8b18666b3f5e28f113fa052692fba.png)

```auto
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

---

<div class="post-metadata">

**Author:** ![meyay](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/meyay/32/34000_2.png) [@meyay](https://forums.docker.com/u/meyay)\
**Post date:** [December 4, 2022, 10:09am UTC](https://forums.docker.com/t/docker-compose-mount-samba-volume/132407/11 "2022-12-04T10:09:26Z")

</div>

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.

```auto
    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.

---

<div class="post-metadata">

**Author:** ![macjames](https://avatars.discourse-cdn.com/v4/letter/m/ed8c4c/32.png) [@macjames](https://forums.docker.com/u/macjames)\
**Post date:** [December 4, 2022, 10:19am UTC](https://forums.docker.com/t/docker-compose-mount-samba-volume/132407/12 "2022-12-04T10:19:20Z")

</div>

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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![meyay](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/meyay/32/34000_2.png) [@meyay](https://forums.docker.com/u/meyay)\
**Post date:** [December 4, 2022, 10:28am UTC](https://forums.docker.com/t/docker-compose-mount-samba-volume/132407/13 "2022-12-04T10:28:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![macjames](https://avatars.discourse-cdn.com/v4/letter/m/ed8c4c/32.png) [@macjames](https://forums.docker.com/u/macjames)\
**Post date:** [December 4, 2022, 10:30am UTC](https://forums.docker.com/t/docker-compose-mount-samba-volume/132407/14 "2022-12-04T10:30:10Z")

</div>

Thanks a lot for your support.

---

<div class="post-metadata">

**Author:** ![macjames](https://avatars.discourse-cdn.com/v4/letter/m/ed8c4c/32.png) [@macjames](https://forums.docker.com/u/macjames)\
**Post date:** [December 4, 2022, 4:10pm UTC](https://forums.docker.com/t/docker-compose-mount-samba-volume/132407/15 "2022-12-04T16:10:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rimelek](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/rimelek/32/41602_2.png) [@rimelek](https://forums.docker.com/u/rimelek)\
**Post date:** [December 4, 2022, 7:23pm UTC](https://forums.docker.com/t/docker-compose-mount-samba-volume/132407/16 "2022-12-04T19:23:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![macjames](https://avatars.discourse-cdn.com/v4/letter/m/ed8c4c/32.png) [@macjames](https://forums.docker.com/u/macjames)\
**Post date:** [December 4, 2022, 7:26pm UTC](https://forums.docker.com/t/docker-compose-mount-samba-volume/132407/17 "2022-12-04T19:26:17Z")

</div>

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