Docker compose 您是否尝试将目录挂载到文件上(或反之亦然)?

Som*_*ver 4 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'
Run Code Online (Sandbox Code Playgroud)

我的文件夹结构如下所示:-

Root
Monitoring_Stack
-- prometheus.yml
-- grafana.ini
-- docker-compose.yml
Run Code Online (Sandbox Code Playgroud)

当我这样做时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.
Run Code Online (Sandbox Code Playgroud)

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

BMi*_*tch 5

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

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