0

I am trying to run the following command

docker run -p 3000:3000 -v/app/node_modules -v $(pwd):/app 2ef0206fcf99

I am getting the following error

docker: Error response from daemon: create $(pwd): "$(pwd)" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intended to pass a host directory, use absolute path.

How can I fix the issue?

msanford
  • 11,803
  • 11
  • 66
  • 93
Muhammad Sharif
  • 406
  • 6
  • 17
  • 1
    One alternative approach is to swap to Docker Compose, even if you have only one container. You can use relative volumes there, e.g. `-v .:/app`, even on Windows. – halfer Jun 05 '20 at 15:43
  • What is the value of `$(pwd)` if you run that in your console? (Maybe edit the question and add that.) Then compare that to the regex it shows in the error. Does it return an error because your running it in a cmd window instead of Powershell (`pwd` doesn't exist in cmd but does in Powershell because it's an alias to `Get-Location`)? Do you _actually have_ illegal characters in your path? Etc... – msanford Jun 05 '20 at 16:04
  • Does this answer your question? [docker : invalid reference format](https://stackoverflow.com/questions/45682010/docker-invalid-reference-format) – msanford Jun 05 '20 at 16:11

2 Answers2

2

1) Using Windows Powershell, following works for me:

docker run --rm -it -v ${pwd}:/mydir nginx:latest bash

Note:

  • I have used curly braces around pwd instead of small braces

2) Using Git Bash, following syntax should work:

winpty docker run --rm -it -v "/$PWD":/mydir nginx:latest bash

Note:

  • If you do not use winpty at the start of the command, you will get error message: the input device is not a TTY. If you are using mintty, try prefixing the command with 'winpty'

  • Also notice the / before $PWD. Without the /, it will not throw error but i noticed that it didn't mount the directory.

Technext
  • 7,887
  • 9
  • 48
  • 76
2

I also had the same issue on windows make sure that you put "$PWD" something like this so your command should be something like this

docker run --rm -it -p 3000:3000 -v "$PWD:/app" 2ef0206fcf99

or another way is

docker run --rm -it -p 3000:3000 --volume="$PWD:/app" 2ef0206fcf99
Dashrath Mundkar
  • 7,956
  • 2
  • 28
  • 42