问题
Configration
Using Windows 10, Docker Toolbox (not native Docker, to be able to use VMs).
Background
There is a Python (2.7) script that is supposed to run a Docker container. The code looks like this:
self.docker.containers.run('container_name',
command='bash -c "%s"' % command,
volumes={PROJECT_PATH: {'bind': '/shared', 'mode': 'rw'}},
working_dir='/shared',
remove=True,
**kwargs)
Problem
Trying to run the script:
* Building the DummyProbe docker image
* Running the DummyProbe container
500 Server Error: Internal Server Error ("invalid volume specification: 'C:\Users\Foo\..:/shared:rw'")
Thoughts
After searching the web the invalid volume specification
is seems to be caused by the way Windows and Linux handle directory structure. Linux uses slashes /
while Windows - back-slashed \
. Similar questions:
- Docker Toolbox Windows - Invalid volume specification
- Invalid volume specification trying to run portainer container
However in my case the COMPOSE_CONVERT_WINDOWS_PATHS
is set (to true
, tried setting to 1
as well):
PowerShell
Docker Toolbox
$ docker-machine env
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://111.111.11.111:1111"
export DOCKER_CERT_PATH="C:\Users\Foo\.docker\machine\machines\default"
export DOCKER_MACHINE_NAME="default"
export COMPOSE_CONVERT_WINDOWS_PATHS="true"
# Run this command to configure your shell:
# eval $("C:\Program Files\Docker Toolbox\docker-machine.exe" env)
None of the suggestions in other questions work.
Update
Tried to use to replace \
with /
and use it in script:
500 Server Error: Internal Server Error ("invalid volume specification: 'C:/Users/***/..:/shared:rw'")
So it seems like it is not an issue
回答1:
I was able to make this work by replacing all \\
with /
and C:
with /c
.
The broken path:
C:\\Path\\to\\file
becomes
/c/path/to/file
https://docs.python.org/2/library/os.html
It seems that os
module which is responsible for returning system paths doesn't have a built-in func to convert Windows to Unix path. And the Docker Toolbox doesn't handle this converstion as well (if it even should).
May be there is some other elegant way to make this work. But for now going to just use this one.
来源:https://stackoverflow.com/questions/53912322/docker-toolbox-windows-invalid-volume-specification