22

What's the difference between these two docker run commands and why one is working and the other does not.

Working Command

docker run --publish=7474:7474 --volume=$HOME/neo4j_test/data:/data neo4j

Not Working

docker run --publish=7474:7474 --volume=C:/Users/USERNAME/neo4j_test/data:/data neoj

docker run --publish=7474:7474 --volume=C:\Users\USERNAME\neo4j_test\data:/data neo4j

Error for these commands

C:\Program Files\Docker Toolbox\docker.exe: Error response from daemon: Invalid bind mount spec "C:UsersUSERNAMEneo4j_testdata:/data": invalid mode: /data. See 'C:\Program Files\Docker Toolbox\docker.exe run --help'.

In the non-working commands, I just replaced $HOME with the absolute path for my user profile folder C:/Users/USERNAME

UPDATE

I did inspect the value for $HOME by executing echo $HOME on Windows Powershell. And it is in fact C:\Users\USERNAME. I also did look at the link that @Titouan Freville has commented. So I used the command

docker run --publish=7474:7474 --volume=/c/Users/USERNAME/neo4j_test/data:/data neo4j

isntead of

docker run --publish=7474:7474 --volume=C:/Users/USERNAME/neo4j_test/data:/data neoj

and it is working now. Right now I'm just wondering where the transformation of $HOME from C:\Users\USERNAME to /c/Users/USERNAME happens

Soviut
  • 88,194
  • 49
  • 192
  • 260
jmc
  • 1,649
  • 6
  • 26
  • 47
  • 1
    Could you provide us with the error message ? You should have one. If it is a not found file, make sure that $HOME == C:/Users/USERNAME also you should look at this post : https://stackoverflow.com/questions/33312662/docker-toolbox-mount-file-on-windows. It could be an answer. – Titouan Freville Oct 24 '16 at 08:42
  • @TitouanFreville please see update :) – jmc Oct 24 '16 at 09:05
  • try `--volume=C:\/Users\/USERNAME/\neo4j_test/\data:/data` – user2915097 Oct 24 '16 at 09:05
  • guess it is the way Docker Machine is interpreting the path. He should transform it to a linux like version compatible with him ;) – Titouan Freville Oct 24 '16 at 09:10

2 Answers2

25

For anyone still having this problem with Docker-for-Windows, here are the 2 solutions that work:

Prefix your command

with MSYS_NO_PATHCONV=1

In full: MSYS_NO_PATHCONV=1 docker run -v /c/path:/path

Use double-slashes

// at the beginning

In full: docker run -v //c/path:/path


Source: https://github.com/moby/moby/issues/24029#issuecomment-250412919

AdrienW
  • 3,092
  • 6
  • 29
  • 59
10

To close the subject. Here is the solution ;) docker toolbox mount file on windows

Also, the interpolation of $HOME by docker on windows have to be compatible with it, so it should transform it by himself when you call it in docker command.

Titouan Freville
  • 489
  • 4
  • 13
  • 5
    Just an additional note to this answer. The drive letter should be in lower case. For instance this will work `/c/Users/USERNAME` and this will not `/C/Users/USERNAME` – jmc Oct 24 '16 at 12:09
  • 3
    If using git-bash on windows add an extra slash, ie: `-v /c/path:/path` to `-v //c/path:/path` – Teebu May 28 '20 at 02:54
  • Or in case of the docker tutorial: `docker run -dp 3000:3000 -w //c/path/to-docker-tutorial/getting-started/app -v "$(pwd):/app" node:12-alpine sh -c "yarn install && yarn run dev"` - so, also the extra slash for the working directory – Flo Bayer Feb 08 '22 at 16:24