如何强制Git for Windows';bash shell是否不将路径字符串转换为windows路径?
我正在使用Git for Windows for Docker toolbox for Windows提供的bash shell。我想将表示unix路径的字符串导出到环境变量,然后在docker容器中使用。比如:如何强制Git for Windows';bash shell是否不将路径字符串转换为windows路径?,bash,docker-compose,environment-variables,git-bash,Bash,Docker Compose,Environment Variables,Git Bash,我正在使用Git for Windows for Docker toolbox for Windows提供的bash shell。我想将表示unix路径的字符串导出到环境变量,然后在docker容器中使用。比如: export MY_VAR=/my/path; docker-compose up echo $MY_VAR # prints c:/Program Files/Git/my/path 问题在于,在我的容器中,变量类似于: export MY_VAR=/my/path; docke
export MY_VAR=/my/path; docker-compose up
echo $MY_VAR # prints c:/Program Files/Git/my/path
问题在于,在我的容器中,变量类似于:
export MY_VAR=/my/path; docker-compose up
echo $MY_VAR # prints c:/Program Files/Git/my/path
因此,shell(我猜)似乎将字符串识别为路径,并将其转换为windows格式。有没有办法阻止这一切
我试图使用MSYS\u NO\u PATHCONV=1
:
MSYS_NO_PATHCONV=1; export LOG_PATH=/my/path; docker-compose up
但没有任何效果
我不认为这是我的docker compose和dockerfile的问题,但如果有人感兴趣,我会附上它们
我的Dockerfile
:
FROM node:8-slim
RUN mkdir /test \
&& chown node:node /test
USER node
ENTRYPOINT [ "/bin/bash" ]
我的docker compose.yml
:
version: '2'
services:
test:
build:
context: .
image: test
environment:
- MY_VAR
volumes:
- ${MY_VAR}:/test
command: -c 'sleep 100000'
version: '2'
services:
test:
build:
context: .
image: test
environment:
- MY_VAR
volumes:
- /${MY_VAR}:/test # added '/' to the beginning of the line
command: -c 'sleep 100000'
这里的最终目标是使主机上的目录可以从docker容器(用于日志等)访问。目录应该由环境变量设置。在
docker compose.yml
中设置目录确实有效,只是不适用于我的用例。似乎一个解决办法是从字符串中删除第一个/
,然后将其添加到docker compose.yml
中
新建docker compose.yml
:
version: '2'
services:
test:
build:
context: .
image: test
environment:
- MY_VAR
volumes:
- ${MY_VAR}:/test
command: -c 'sleep 100000'
version: '2'
services:
test:
build:
context: .
image: test
environment:
- MY_VAR
volumes:
- /${MY_VAR}:/test # added '/' to the beginning of the line
command: -c 'sleep 100000'
然后用以下命令启动容器:
export MY_VAR=my/path; docker-compose up # removed the '/' from the beginning of the path.
这看起来更像是一个“幸运”的解决方案,而不是一个完美的解决方案,因为当我在其他系统上构建这个时,我必须提醒自己删除/
。可行,但有点烦人。也许有人有更好的主意。也许是复制品:或者这个: