cod*_*urn 5 docker docker-compose
volumes
我正在尝试在我的 .conf 部分安装一个文件(nginx.conf)docker-compose.yml
。我可以毫无问题地将目录挂载为卷,但是,我不清楚文件的语法是什么。
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
Run Code Online (Sandbox Code Playgroud)
后来,我的服务部分下有以下内容
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
Run Code Online (Sandbox Code Playgroud)
当我尝试启动它时,我收到以下错误:
错误:对于 roundcube_nginx_1 无法为服务 nginx 创建容器:无法安装本地卷:mount /mnt/docker /volumes/roundcube/nginx.conf:/var/lib/docker/volumes/roundcube_nginxconf/_data,标志:0x1000:不是目录
错误:对于 nginx 无法为服务 nginx 创建容器:无法安装本地卷:mount /mnt/docker/volumes/rou ndcube/nginx.conf:/var/lib/docker/volumes/roundcube_nginxconf/_data,标志:0x1000:不是目录错误:启动项目时遇到错误。
我发现,如果我将文件位置内联到 nginx 服务部分的卷声明中,那么它就可以正常工作。例如:
volumes:
- roundcubeweb:/var/www/html
- /mnt/docker/volumes/roundcube/nginx.conf:/etc/nginx/conf.d/default.conf
Run Code Online (Sandbox Code Playgroud)
不能在该volumes
部分挂载文件吗?有本地驱动参数参考吗?
我认为不可能让独立的 Docker 卷指向特定文件而不是目录。它可能与 Docker 设计有关如何管理和安装卷有关(试图找到文档或相关代码段,但找不到任何)
local
驱动程序的参数似乎采用与 Linuxmount
命令类似的参数。Docker 卷文档中似乎暗示了这一点,尽管不是很清楚:
本地驱动程序接受挂载选项作为 o 参数中逗号分隔的列表
我发现,如果我将文件位置内联到 nginx 服务部分的卷声明中,那么它就可以正常工作。例如:
Run Code Online (Sandbox Code Playgroud)volumes: - roundcubeweb:/var/www/html - /mnt/docker/volumes/roundcube/nginx.conf:/etc/nginx/conf.d/default.conf
在您的示例中,您正在执行Bind Mound而不是使用Volumes ,Docker 的处理方式有所不同,并且更适合您在容器中安装本地文件的用例。我认为使用 Bind Mount 是适合您情况的解决方案。
归档时间: |
|
查看次数: |
8519 次 |
最近记录: |