获取类型 "bind" 的无效挂载配置:docker 中不存在绑定源路径

Getting invalid mount config for type "bind": bind source path does not exist in docker

我正在尝试将以下 docker-compose 部署到 docker swarm 集群中。

version: '3.2'
services:
  jenkins:
    image: jenkins/jenkins:lts
    ports:
      - 8080:8080
    volumes:
      - ./data_jenkins:/var/jenkins_home
    deploy:
      mode: replicated
      replicas: 1

我在 docker-compose 所在的相同位置确实有 data_jenkins 并将该路径作为 volume 传递。但是为什么会抛出源路径不存在。到底是什么问题。

Also if the directory doesnot exist -v should have created it right. Why is it not ?

这在 Docker Swarm BIND MOUNTS

中有明确记录

If you bind mount a host path into your service’s containers, the path must exist on every swarm node. The Docker swarm mode scheduler can schedule containers on any machine that meets resource availability requirements and satisfies all constraints and placement preferences you specify.

与运行 单个容器不同,bind-mount host 目录如果不退出则不会创建。它必须先于 运行 集群节点上的容器存在。