如何在 Docker Portainer 中的 Windows 主机上挂载现有目录?

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

我有docker-compose.yml

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

我可以用 docker-compose up 做到这一点,没有任何问题

但是在 portainer 堆栈中,我得到了一个错误

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  

基本上我想映射我的主机文件夹 D:/Docker/config。我如何在 portainer 中执行此操作?

使用 /d/Downloads 使其工作,感谢 @xerx593

我花了很长时间弄清楚这个问题

因此在 Docker-Compose 中,在 Windows 运行 Docker 桌面上,当输入绑定安装的安装点时,您必须格式化它

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

一个例子是

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

您还可以选择使用 Compose 文件所在位置的相对路径,但对于 Portainer,这不是一个选项。我知道,我尝试了我能想到的一切。然后我在看教程,我看到了@warheat1990 在这里发布的同样的东西并进行了试验。

Portainer 告诉您粘贴 Docker-Compose,但路径不同。 Portainer 内的路径将无法工作并被忽略或放置在您无法从 windows 访问它们的地方,除非您删除“/mnt”并以驱动器号开头

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

一个例子是

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

我在没有“/mnt”的 Portainer 之外测试了它,但它失败了,但在 Portainer 中它不可能存在。到目前为止,我相当有信心没有办法做到对两者都有效。这非常烦人,因为 Portainer 可以轻松粘贴您的 Compose 或实际导入文件,但您必须对其进行编辑,只是没有人告诉您...

希望对您有所帮助