使用Docker for windows将windows驱动器卷装到Linux容器中



我正在使用Docker Desktop for Windows,我想在Linux容器中查找Docker创建卷的位置?

有人能够执行我试图实现的卷安装吗?

如果您只是想将windows路径挂载到基于Linux的容器,这里有一个使用基本docker run命令的示例,还有一个Docker Compose示例:

docker run -d --name qbittorrent -v '/mnt/f/Fetched Media/Unsorted:/downloads' -v '/mnt/f/Fetched Media/Blackhole:/blackhole' linuxserver/qbittorrent

此示例将Windows主机上的f:Fetched MediaUnsortedf:Fetched MediaBlackhole文件夹共享到容器;在Linux容器中,您可以看到这些Windows文件夹中的文件,它们各自的Linux路径显示在冒号的右侧。

即CCD_ 4文件夹将在Linux容器中的CCD_。

*首先,请确保您已经在GUI的Docker Desktop设置区域中共享了这些Windows文件夹。


WSL(2(的更新

您不需要专门共享Windows文件夹路径;只有当而不是使用WSL时才需要。


更新

这似乎是一个流行的答案,所以为了彻底起见,我想我还应该包括上面例子的Docker Compose版本(包括如何将路径设置为读写(rw(或只读(ro((:

qbittorrent:
image: 'linuxserver/qbittorrent:latest'
volumes:
- '/mnt/f/Fetched Media/Unsorted:/downloads:rw'
- '/mnt/f/Fetched Media/Blackhole:/blackhole:rw'
- '/mnt/e/Logs/qbittorrent:/config/logs:rw'
- '/opt/some-local-folder/you-want/read-only:/some-folder-inside-container:ro'

我不确定为什么需要这样做,但如果其他人遇到这个问题:我必须将整个卷声明用双引号括起来,如下所示

docker run -d --name qbittorrent -v "/mnt/f/Fetched Media/Unsorted:/downloads" -v "/mnt/f/Fetched Media/Blackhole:/blackhole" linuxserver/qbittorrent

除此之外,J.Scott Elblein的回答非常有效!

最新更新