首页 > 解决方案 > 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.

任何帮助将不胜感激我做错了什么?谢谢你。

标签: dockerdocker-compose

解决方案


对于主机卷,如果源不存在,它将由 docker 创建为空目录(否则绑定挂载将失败)。如果容器内的目标是文件,这将不起作用。

您的目录结构中没有该文件./prometheus/prometheus.yml。相反,您有一个./prometheus.yml. grafana 也类似。左边的路径是你主机上的路径,在容器之外。冒号后面是容器内的路径。


推荐阅读