[英]docker-compose volumes syntax for local driver to mount a file
我正在尝试在我的docker-compose.yml
的volumes
部分安装一个文件(nginx.conf)。 我可以毫无问题地将目录挂载为卷,但是,我不清楚文件的语法是什么。
我在我的volumes
部分定义了以下内容
volumes:
roundcubeweb:
driver: local
driver_opts:
type: none
o: bind
device: /mnt/docker/volumes/roundcube/html
nginxconf:
driver: local
driver_opts:
type: none
o: bind
device: /mnt/docker/volumes/roundcube/nginx.conf
稍后,我的服务部分下有以下内容
nginx:
image: nginx:latest
deploy:
replicas: 1
restart: always
depends_on:
- roundcube
ports:
- "8082:80"
volumes:
- roundcubeweb:/var/www/html
- nginxconf:/etc/nginx/conf.d/default.conf
当我尝试启动它时,我收到以下错误:
错误:对于roundcube_nginx_1无法为服务nginx创建容器:无法挂载本地卷:挂载/mnt/docker /volumes/roundcube/nginx.conf:/var/lib/docker/volumes/roundcube_nginxconf/_data,标志:0x1000:不是目录
错误:对于 nginx 无法为服务 nginx 创建容器:无法挂载本地卷:挂载 /mnt/docker/volumes/rou ndcube/nginx.conf:/var/lib/docker/volumes/roundcube_nginxconf/_data,标志:0x10000000目录错误:启动项目时遇到错误。
我发现如果我在 nginx 服务部分的卷声明中内联文件位置,那么它就可以正常工作。 例如:
volumes:
- roundcubeweb:/var/www/html
- /mnt/docker/volumes/roundcube/nginx.conf:/etc/nginx/conf.d/default.conf
不能在volumes
部分挂载文件吗? 本地驱动的参数有参考吗?
我认为不可能让独立的 Docker 卷指向特定文件而不是目录。 它可能与有关如何管理和安装卷的 Docker 设计有关(试图找到文档或相关代码,但找不到任何内容)
local
驱动程序的参数似乎采用与 Linux mount
命令类似的参数。 Docker 卷文档中似乎暗示了这一点,尽管不是很清楚:
本地驱动程序接受挂载选项作为 o 参数中的逗号分隔列表
我发现如果我在 nginx 服务部分的卷声明中内联文件位置,那么它就可以正常工作。 例如:
volumes: - roundcubeweb:/var/www/html - /mnt/docker/volumes/roundcube/nginx.conf:/etc/nginx/conf.d/default.conf
在您的示例中,您正在执行Bind Mound而不是使用Volumes ,Docker 的处理方式不同,更适合您在容器中安装本地文件的用例。 我认为在您的情况下使用 Bind Mount 是合适的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.