22

I am trying to deploy following docker-compose into docker swarm cluster.

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

I do have the data_jenkins in the same locations where docker-compose is and passing that path as volume . But why is it throwing the source path does not exist. What exactly is the problem.

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

Tara Prasad Gurung
  • 3,422
  • 6
  • 38
  • 76
  • This is the problem I have figured out. the path may be available in one of the cluster but not in another cluster. Running in manager node works. But why is the -v not creating a directory to whichever node it is running – Tara Prasad Gurung Feb 25 '18 at 07:24
  • For me, downgrading docker-compose version helped – Abhi May 13 '22 at 19:06

1 Answers1

45

This is clearly documented in 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.

Unlike running a single container, the bind-mount host directory is not created if it doesn't exit. It must exist prior to running the container on a cluster node.

x-yuri
  • 16,722
  • 15
  • 114
  • 161
yamenk
  • 46,736
  • 10
  • 93
  • 87
  • 1
    Absolutely thats what it is to solve the problem I have used named container instead of passing the host path. Thanks I was unaware of scheduler too. Accepted answer – Tara Prasad Gurung Feb 25 '18 at 14:18
  • 10
    @TaraPrasadGurung Could u please describe what did u do to solve the problem? – Rahman Jan 16 '21 at 10:12
  • It is also possible to restrict the placement in the "deply" section to a specific server where the directory exists. – Stefan A Jul 08 '22 at 16:27
  • For those still struggling with this. I had to make sure the directory I wanted to bind mount into my container existed _relatively_ to my docker swam yml file. I was trying to create a bind mount from outside the context of the build/swarm directory which didn't work. – ConfusedCopyPaster Jul 23 '23 at 15:52