[英]Windows 10 bind mounts in docker-compose not working
I'm using docker-compose to manage a multi container application. 我正在使用docker-compose管理多容器应用程序。 1 of those containers needs access to the contents of a directory on the host.
这些容器中的1个需要访问主机上目录的内容。
This seems simple according to the various sources of documentation on docker and docker-compose but I'm struggling to get it working. 根据有关docker和docker-docker的各种文档来源,这似乎很简单,但我正在努力使其正常运行。
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: 运行此错误消息:
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.
错误:服务“ event_processor”中使用了名为“ C / path / to / interesting / directory:/ interesting_directory:rw”的卷,但在卷部分未找到声明。
I understand from the docs that a top level declaration is only necessary if data is to be shared between containers 我从文档中了解到,只有在容器之间共享数据时才需要顶层声明
which isn't the case here. 这里不是这种情况。
The docs for docker-compose I linked above have an example which seems to do exactly what I need: 上面链接的docker-compose文档有一个示例,它似乎完全可以满足我的需要:
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: 但是,当我尝试时,出现有关语法的错误:
ERROR: The Compose file '.\\docker-compose.yaml' is invalid because: services.audio_event_processor.volumes contains an invalid type, it should be a string
错误:撰写文件'。\\ docker-compose.yaml'无效,原因是:services.audio_event_processor.volumes包含无效的类型,应为字符串
So I tried to play along: 所以我尝试一起玩:
volumes:
- type: "bind"
source: "C/path/to/interesting/directory"
target: "/interesting_directory"
ERROR: The Compose file '.\\docker-compose.yaml' is invalid because: services.audio_event_processor.volumes contains an invalid type, it should be a string 错误:撰写文件'。\\ docker-compose.yaml'无效,原因是:services.audio_event_processor.volumes包含无效的类型,应为字符串
So again the same error. 因此再次出现相同的错误。
I tried the following too: 我也尝试了以下方法:
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
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. 因此,似乎可以用1个字符串创建多个卷(尽管在这种情况下,正斜杠会剪切字符串),但我没有将其映射到主机目录。
I've read the docs but I think I'm missing something. 我已经阅读了文档,但我想我缺少了一些东西。 Can someone post an example of mounting aa windows directory from a host to a linux container so that the existing contents of the windows dir is available from the container?
有人可以发布一个将Windows目录从主机安装到Linux容器的示例,以便可以从容器中获取Windows目录的现有内容吗?
OK so there were multiple issues here: 好,所以这里有多个问题:
1. 1。
I had 我有
version: '3'
at the top of my docker-compose.yml. 在我的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:
此处描述的长语法直到3.4才实现,因此当我将其更新为以下内容时,我不再收到奇怪的语法错误:
version: '3.6'
2. 2。
I use my my docker account on 2 windows PCs. 我在2台Windows PC上使用我的docker帐户。 Following a hint from another stackoverflow post, I reset Docker to the factory settings.
在另一个stackoverflow帖子中提示之后,我将Docker重置为出厂设置。 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.
我必须给docker计算机的用户名和密码,并注意这对于访问本地文件系统的内容是必要的-此时,我记得在另一台PC上进行了此操作,因此我不确定凭据在此是否正确。 With the correct credentials for the current PC, I was able to bind-mount the volume with the expected results as follows:
使用当前PC的正确凭据,我可以将卷与预期结果绑定安装,如下所示:
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
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.
明天使用另一台PC进行更新时,我会找出答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.