Windows 10绑定在docker-compose中的安装不起作用 [英] Windows 10 bind mounts in docker-compose not working
问题描述
我正在使用docker-compose管理多容器应用程序。这些容器中的1个需要访问主机上目录的内容。
I'm using docker-compose to manage a multi container application. 1 of those containers needs access to the contents of a directory on the host.
根据docker和docker-compose的各种文档来源,这似乎很简单,但我我努力使它正常工作。
This seems simple according to the various sources of documentation on docker and docker-compose but I'm struggling to get it working.
event_processor:
environment:
- COMPOSE_CONVERT_WINDOWS_PATHS=1
build: ./Docker/event_processor
ports:
- "15672:15672"
entrypoint: python -u /src/event_processor/event_processor.py
networks:
- app_network
volumes:
- C/path/to/interesting/directory:/interesting_directory"
正在运行这我得到错误消息:
Running this I get the error message:
错误:命名卷
C / path / to / interesting / directory:/ interesting_directory :rw用于
服务 event_processor,但未在
卷部分中找到声明。
ERROR: Named volume "C/path/to/interesting/directory:/interesting_directory:rw" is used in service "event_processor" but no declaration was found in the volumes section.
我从文档中了解到,仅当要获取数据时才需要顶层声明在容器之间共享
在这里不是这种情况。
我在上面链接的docker-compose文档中有一个示例似乎完全满足我的需要:
The docs for docker-compose I linked above have an example which seems to do exactly what I need:
version: "3.2"
services:
web:
image: nginx:alpine
ports:
- "80:80"
volumes:
- type: volume
source: mydata
target: /data
volume:
nocopy: true
- type: bind
source: ./static
target: /opt/app/static
networks:
webnet:
volumes:
mydata:
但是,当我尝试时,会出现语法错误:
However when I try, I get errors about the syntax:
错误:撰写文件'.\docker-compose.yaml'无效,因为:
services.audio_event_processor.volumes包含无效类型,它
应该是一个字符串
ERROR: The Compose file '.\docker-compose.yaml' is invalid because: services.audio_event_processor.volumes contains an invalid type, it should be a string
所以我试着玩:
volumes:
- type: "bind"
source: "C/path/to/interesting/directory"
target: "/interesting_directory"
错误:撰写文件。 \docker-compose.yaml'无效,因为:
services.audio_event_processor.volumes包含无效类型,应为字符串
ERROR: The Compose file '.\docker-compose.yaml' is invalid because: services.audio_event_processor.volumes contains an invalid type, it should be a string
因此再次相同错误。
我也尝试了以下操作:
volumes:
- type=bind, source=C/path/to/interesting/directory,destination=/interesting_directory
没有错误,但附加到正在运行的容器,我看到以下两个文件夹;
No error, but attaching to the running container, I see the following two folders;
type=bind, source=C
所以看来我能够用1个字符串创建许多卷(尽管向前在这种情况下,斜杠会截断字符串),但我没有将其映射到主机目录。
So it seems that I am able to create a number of volumes with 1 string (though the forward slashes are cutting the string in this case) but I am not mapping it to the host directory.
我已经阅读了文档,但是我想缺少一些东西。
有人可以举一个将Windows目录从主机安装到Linux容器的示例,以便可以从容器中获取Windows目录的现有内容吗?
I've read the docs but I think I'm missing something. Can someone post an example of mounting a a windows directory from a host to a linux container so that the existing contents of the windows dir is available from the container?
推荐答案
好,所以这里有多个问题:
OK so there were multiple issues here:
1。
我有
version: '3'
在我的docker-compose.yml顶部。在此处描述的长语法直到才实现因此,当我将其更新为:
at the top of my docker-compose.yml. The long syntax described here wasn't implemented until 3.4 so I stopped receiving the bizarre syntax error when I updated this to:
version: '3.6'
2。
我在2台Windows PC上使用我的docker帐户。在另一个stackoverflow帖子中提示之后,我将Docker重置为出厂设置。我必须给docker计算机的用户名和密码,并注意这是访问本地文件系统的内容所必需的-此时,我记得在另一台PC上进行了此操作,因此我不确定凭据在此是否正确。有了当前PC的正确凭据,我就可以将卷与预期结果绑定安装,如下所示:
I use my my docker account on 2 windows PCs. Following a hint from another stackoverflow post, I reset Docker to the factory settings. I had to give docker the computer username and password with the notice that this was necessary to access the contents of the local filesystem - at this point I remembered doing this on another PC so I'm not sure whether the credentials were correct on this on. With the correct credentials for the current PC, I was able to bind-mount the volume with the expected results as follows:
version: '3.6'
event_processor:
environment:
- COMPOSE_CONVERT_WINDOWS_PATHS=1
build: ./Docker/event_processor
ports:
- "15672:15672"
entrypoint: python -u /src/event_processor/event_processor.py
networks:
- app_network
volumes:
- type: bind
source: c:/path/to/interesting/directory
target: /interesting_directory
现在它可以按预期工作。我不确定是修复了出厂设置还是更新了凭据。明天我会在使用另一台PC进行更新时找到答案。
Now it works as expected. I'm not sure if it was the factory reset or the updated credentials that fixed it. I'll find out tomorrow when I use another PC and update.
这篇关于Windows 10绑定在docker-compose中的安装不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!