swarm mode doesn't recognize absolute path in windows

339 views Asked by At

I am following Bret Fisher's docker course and I got this assignment. I am running on windows and created 3 virtual nodes with docker-machine. All three nodes are connected in a swarm (2 managers, 1 worker). I am trying to run the following command:

docker service create --network backend --mount type=volume,source=db-data,target=/var/lib/postgresql/data --name db -e POSTGRES_HOST_AUTH_METHOD=trust postgres:9.4

when I run in powershell, It works fine. When I try to run it in GitBash or cmder I get the error:

invalid mount target, must be an absolute path <the path of cli in used>

I tried to change the target to:

  1. different paths
  2. pwd/ $pwd / $(pwd) / ${pwd}
  3. wsl wslpath $(pwd)

p.s. When I run the stack example of the same code, it does run in GitBash/ Cmder and powershell.

2

There are 2 answers

1
Bret Fisher On

Did you try quoting the mount value?

docker service create --network backend --mount "type=volume,source=db-data,target=/var/lib/postgresql/data" --name db -e POSTGRES_HOST_AUTH_METHOD=trust postgres:9.4
0
Tms91 On

Check if you are working in a directory that contains spaces.

When using mounts and volumes (-v), Docker cannot handle this case with Bash on Windows, no matter which escape characters you try.

The only way I found to solve this is to switch your current directory to one in which no folder contains spaces.

Even the use of $(pwd) inside -v input is a problem, see here, there is also a list of escape characters I tried to use to solve the problem.