docker - 无法使用 docker-compose 挂载文件
问题描述
我跑docker-compose -f docker-compose.prod.yml up
了,我立即得到错误:
ERROR: for frontend Cannot start service frontend: OCI runtime create failed: container_linux.go:348: starting container process caused "process_linux.go:402: container init caused \"rootfs_linux.go:58: mounting \\\"/c/Users/James/Projects/mysite/frontend/conf/nginx/mysite.template\\\" to rootfs \\\"/var/lib/docker/aufs/mnt/e7a2a699ae3e9ede0dd60b7cfdebb7f2d3adf71e8175157f3c9e88d3285796d2\\\" at \\\"/var/lib/docker/aufs/mnt/e7a2a699ae3e9ede0dd60b7cfdebb7f2d3adf71e8175157f3c9e88d3285796d2/etc/nginx/conf.d/default.conf\\\" caused \\\"not a directory\\\"\"": unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type
我的mysite.template
文件存在。我正在使用带有docker-machine
. 在开发中,我没有在同一个操作系统(ubuntu 16)上运行这个问题。我在 windows 上使用 docker 工具箱进行开发。
这是来自的前端配置docker-compose.prod.yml
:
frontend:
image: nginx:stable-alpine
restart: always
networks:
- web
- default
volumes:
- ${PWD}/frontend/conf/nginx/mysite.template:/etc/nginx/conf.d/default.conf
- ${PWD}/frontend/public:/var/www/html
labels:
- "traefik.enable=true"
- "traefik.basic.frontend.rule=Host:mysite.com"
- "traefik.basic.port=80"
我按照文档中的说明进行操作。任何想法出了什么问题?
解决方案
您只能将主机目录挂载为卷,而不是 Docker 中的单个文件。
在您的volumes
定义中,而不是这样:
- ${PWD}/frontend/conf/nginx/mysite.template:/etc/nginx/conf.d/default.conf
你应该做这个:
- ${PWD}/frontend/conf/nginx:/etc/nginx/conf.d
推荐阅读
- r - 使用 r2d3 在 d3.js 中使用 R data.frame 对象
- python - 使用 tf-coreml 将 Tensorflow 转换为 coreML 时出错
- json - 将“字符串”转换为不相关类型“NSDictionary”总是在 Swift 的注册表单中失败
- android - Unity + ARCore:点云没有颜色选择器
- rust - 使用 Cell 会产生哪些费用
而不仅仅是 T? - android - 注销广播接收器中的问题
- c# - C# TCP 服务器一次接收 Python 客户端发送的两条消息
- perl - 将 GooCanvas2 保存为 PNG 文件
- laravel - Laravel 5.1 - 身份验证 - 当用户注销时,主页不会重定向到登录页面
- ios - 部署到 Apple 商务管理客户