Docker Toolbox (Windows): invalid volume specification

我怕爱的太早我们不能终老 提交于 2021-02-08 06:29:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!