Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Docker via Windows console: includes invalid characters $PWD for a local volume name

I try to run a Python program with Docker via the Windows console (Windows 10).

I had made the Windows console be capable of Docker Hello, World!.

But when I run:

 docker run -it --rm --name my-running-script -v "$PWD":/usr/src/myapp -w /usr/src/myapp python:2 python test.py

I get the error:

docker: Error response from daemon: create $PWD: volume name invalid:
"$PWD" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed.

See 'docker run --help'.

While running the same code via Docker Quickstart Terminal, it runs well.

I tried to, but I can't solve it. How can I do it?

like image 322
qingkejin Avatar asked Mar 03 '16 09:03

qingkejin


3 Answers

I think, the substitution of Linux command $(pwd) in Windows is "%cd%".

So, try out following command which might help you.

docker run -it --rm --name my-running-script -v "%cd%":/usr/src/myapp -w /usr/src/myapp python:2 python test.py
like image 187
Naveen Kumar G C Avatar answered Nov 06 '22 08:11

Naveen Kumar G C


Read the documentation: Manage data in containers

If you are using Docker Machine on Mac or Windows, your Docker daemon has only limited access to your OS X or Windows filesystem. Docker Machine tries to auto-share your /Users (OS X) or C:\Users (Windows) directory.

So, you can mount files or directories on OS X using:

docker run -v /Users/<path>:/<container path> ...

On Windows, mount directories using:

docker run -v /c/Users/<path>:/<container path> ...`

My Docker Machine is on Windows, so instead of ' "$PWD" ' like:

docker run -it --rm --name my-running-script -v "$PWD":/usr/src/myapp -w /usr/src/myapp python:2 python test.py

Use ' /c/Users/your_name ' like:

docker run -it --rm --name my-running-script -v /c/Users/cn_pa:/usr/src/myapp -w /usr/src/myapp python:2 python test.py
like image 14
qingkejin Avatar answered Nov 06 '22 07:11

qingkejin


if you use a bash command line on windows, you will works just placing a / before $ PWD. Something like:

docker run -v /$PWD:/src
like image 12
Brian Avatar answered Nov 06 '22 09:11

Brian