首页 > 解决方案 > Docker 工具箱 (Windows):无效的卷规范

问题描述

配置

使用 Windows 10,Docker Toolbox(不是原生 Docker,能够使用 VM)。

背景

有一个 Python (2.7) 脚本应该运行 Docker 容器。代码如下所示:

self.docker.containers.run('container_name',
                           command='bash -c "%s"' % command,
                           volumes={PROJECT_PATH: {'bind': '/shared', 'mode': 'rw'}},
                           working_dir='/shared',
                           remove=True,
                           **kwargs)

问题

尝试运行脚本:

* Building the DummyProbe docker image
* Running the DummyProbe container   
500 Server Error: Internal Server Error ("invalid volume specification: 'C:\Users\Foo\..:/shared:rw'")

想法

在网上搜索后,invalid volume specification似乎是由 Windows 和 Linux 处理目录结构的方式引起的。Linux 使用斜杠/,而 Windows使用反斜杠\。类似的问题:

但是在我的情况下,COMPOSE_CONVERT_WINDOWS_PATHS设置为(到true,也尝试设置1为):

电源外壳

在此处输入图像描述

码头工人工具箱

$ 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)

其他问题中的建议均无效。

更新

尝试使用替换\/在脚本中使用它:

500 Server Error: Internal Server Error ("invalid volume specification: 'C:/Users/***/..:/shared:rw'")

所以这似乎不是问题

标签: dockerdocker-toolbox

解决方案


我能够通过将所有内容替换\\/C:来完成这项工作/c

破碎的路径: C:\\Path\\to\\file 变成 /c/path/to/file

https://docs.python.org/2/library/os.html

似乎os负责返回系统路径的模块没有内置函数来将 Windows 转换为 Unix 路径。并且 Docker Toolbox 也不处理这种转换(如果它应该处理的话)。

可能还有其他一些优雅的方式来完成这项工作。但现在只使用这个。


推荐阅读