我正在使用 docker-compose 来管理多容器应用程序。其中 1 个容器需要访问主机上目录的内容。
根据 docker 和 docker-compose 上的各种文档来源,这似乎很简单,但我正在努力让它工作。
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"
运行这个我收到错误消息:
错误:命名卷
“C/path/to/interesting/directory:/interesting_directory:rw”用于
服务“event_processor”,但在中找不到声明
卷部分。
我从文档中了解到,只有在容器之间共享数据时才需要顶级声明 https://docs.docker.com/compose/compose-file/#volumes
但这里的情况并非如此。
我上面链接的 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:
但是,当我尝试时,我收到有关语法的错误:
错误:Compose 文件“.\docker-compose.yaml”无效,因为:
services.audio_event_processor.volumes 包含无效类型,它
应该是一个字符串
所以我试着一起玩:
volumes:
- type: "bind"
source: "C/path/to/interesting/directory"
target: "/interesting_directory"
错误:Compose 文件“.\docker-compose.yaml”无效,因为:
services.audio_event_processor.volumes 包含无效类型,它应该是一个字符串
所以又出现同样的错误。
我也尝试了以下方法:
volumes:
- type=bind, source=C/path/to/interesting/directory,destination=/interesting_directory
没有错误,但是附加到正在运行的容器,我看到以下两个文件夹;
type=bind, source=C
因此,我似乎能够使用 1 个字符串创建多个卷(尽管在本例中正斜杠正在剪切字符串),但我没有将其映射到主机目录。
我已阅读文档,但我认为我遗漏了一些东西。
有人可以发布一个将 Windows 目录从主机安装到 Linux 容器的示例,以便容器中可以使用 Windows 目录的现有内容吗?