'How to mount existing directory on Windows Host in Docker Portainer?

I have docker-compose.yml

volumes:
      - D:/Docker/config:/config
      - D:/Downloads:/downloads  

I can do this with docker-compose up without any issue

But in portainer stack, I got an error

Deployment error
failed to deploy a stack: Named volume "D:/Docker/config:/config" is used in service "test" but no declaration was found in the volumes section. : exit status 1  

Basically I want to map my host folder D:/Docker/config. How do I do this in portainer?



Solution 1:[1]

use /d/Downloads to make it work, thanks to @xerx593

Solution 2:[2]

I spent a long time figuring this out

So in Docker-Compose, on Windows running Docker Desktop in WSL2 mode when entering a mount point for a Bind Mount you have to format it

- /mnt/DRIVE-LETTER/directory/to/location:/container/path

An example would be

- /mnt/k/docker/tv/xteve/config:/home/xteve/config

You also have the option of using relative paths from where the Compose file is located but with Portainer that isn't an option. I know, I tried everything I could think of. Then I was looking at tutorials & I saw the same thing @warheat1990 posted here & experimented with that.

Portainer tells you to paste your Docker-Compose, but the paths are different. The paths inside Portainer will not work & be ignored or placed somewhere you can't get to them from windows, unless you remove the "/mnt" & start with the drive letter

- /DRIVE-LETTER/directory/to/location:/container/path

An example would be

- /k/docker/tv/xteve/config:/home/xteve/config

I tested it & outside of Portainer without the "/mnt" it fails, but within Portainer it can't be there. So far I'm fairly confident that there is no way to do it that works for both. Which is super annoying because Portainer makes it easy to paste your Compose or actually import the file, but then you must edit it, just nobody tells you that...

Hope that helps

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 warheat1990
Solution 2 Leon Bob Noël