docker - Docker compose 您是否尝试将目录挂载到文件上(反之亦然)?
问题描述
我在 Docker 版本 20.07 上,我正在尝试挂载我的配置文件。
我的 Docker 撰写看起来像这样-:
version: '2'
services:
prometheus:
image: prom/prometheus
ports:
- '9090:9090'
container_name: prometheus
restart: always
volumes:
- './prometheus/prometheus.yml:/etc/prometheus/prometheus.yml'
grafana:
image: grafana/grafana
ports:
- '3000:3000'
container_name: grafana
restart: always
depends_on:
- prometheus
volumes:
- './grafana/config/grafana.ini:/etc/grafana/grafana.ini'
我的文件夹结构如下所示:-
Root
Monitoring_Stack
-- prometheus.yml
-- grafana.ini
-- docker-compose.yml
当我这样做时docker-compose up -d
,我不断得到:-
ERROR: for prometheus Cannot start service prometheus: OCI runtime create failed: container_linux.go:380: starting container process caused: process_linux.go:545: container init caused: rootfs_linux.go:76: mounting "/run/desktop/mnt/host/d/Docker/monitoring_stack/prometheus/prometheus.yml" to rootfs at "/etc/prometheus/prometheus.yml" caused: mount through procfd: 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
ERROR: Encountered errors while bringing up the project.
任何帮助将不胜感激我做错了什么?谢谢你。
解决方案
对于主机卷,如果源不存在,它将由 docker 创建为空目录(否则绑定挂载将失败)。如果容器内的目标是文件,这将不起作用。
您的目录结构中没有该文件./prometheus/prometheus.yml
。相反,您有一个./prometheus.yml
. grafana 也类似。左边的路径是你主机上的路径,在容器之外。冒号后面是容器内的路径。
推荐阅读
- reactjs - 我可以知道我在 react js 中导入了我的组件吗?
- numpy - 试图理解这段代码在做什么
- tcp - gRPC 在 TCP 数据包上设置 PSH 标志
- debugging - 如何使用箭头键在 gdb 命令窗口中编辑命令?
- amazon-web-services - AWS Secrets Manager with Database inside RDS (Postgres) - 如何在 RDS 实例中存储数据库的密码?
- python - 在自定义类中包装记录器时出现问题
- node.js - Expressjs - 同一 URL 上的重复 GET 请求(一种类型的文档,一种类型的文本/html)
- python - 为什么我的代码不断重复问题提示而不是进入条件语句?
- github - 如何将 Github Gist 转移到存储库?
- python - Python 套接字和线程问题