docker - 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'")
所以这似乎不是问题
解决方案
我能够通过将所有内容替换\\
为/
和C:
来完成这项工作/c
。
破碎的路径:
C:\\Path\\to\\file
变成
/c/path/to/file
https://docs.python.org/2/library/os.html
似乎os
负责返回系统路径的模块没有内置函数来将 Windows 转换为 Unix 路径。并且 Docker Toolbox 也不处理这种转换(如果它应该处理的话)。
可能还有其他一些优雅的方式来完成这项工作。但现在只使用这个。
推荐阅读
- c# - 在实体框架代码中,日期时间总是更改为时间戳
- php - 自定义 Wordpress 页面 IFrame 问题
- javascript - .match() 更改文本后不起作用。| JavaScript, 角
- flutter - 更改 cupertino_icons 中的图标颜色
- python - 在网格 Tkinter 窗口中对齐小部件
- python - 将格式化为元组列表的字符串转换为元组列表
- php - 为什么我的 Laravel 8.0 会话不起作用?
- excel - 将点击事件添加到命令按钮
- php - 如何更改索引页面中包含的获取页面的 SQL 查询
- openoffice-calc - 如何从另一个文档运行脚本