Search code examples
dockerdocker-composedocker-volume

Docker volume mapping folder issue on Windows 10


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?


Solution

  • 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.