You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows环境下Docker挂载卷时Linux格式路径被追加;C的问题求助

Fix Docker Volume Mount Error with $PWD in Git Bash/PowerShell on Windows

This is a super common gotcha with Git Bash on Windows, thanks to its over-helpful automatic path conversion behavior. Let's break down why this happens and how to fix it quickly.

Why the Error Happens

Git Bash tries to translate Unix-style paths (like /d/my/project/folder) to Windows-style paths (D:\my\project\folder) when passing them to Windows programs (like Docker Desktop). But when you append :/wkDir to $PWD, Git Bash misinterprets the colon as a separator for Windows drive letters. It then grabs the first drive letter from your PATH environment variable (usually C:) and tacks it on, turning your valid path into the broken D:/my/project/folder;C you're seeing.

Solutions

1. Disable Git Bash Path Conversion (Simplest Fix)

Add the MSYS_NO_PATHCONV=1 environment variable before your Docker command to turn off automatic path conversion entirely. This tells Git Bash to pass the Unix-style path as-is to Docker.

Update the Docker line in your .sh script to:

MSYS_NO_PATHCONV=1 docker run -v "$PWD:/wkDir" your-dev-image-name

You can also set this variable globally for your Git Bash session by adding export MSYS_NO_PATHCONV=1 at the top of your script.

2. Convert Path to Windows Format Explicitly

Use Git Bash's built-in cygpath tool to convert the Unix-style $PWD to a proper Windows path (with backslashes), which Docker understands perfectly.

Modify your script line to:

docker run -v "$(cygpath -w $PWD):/wkDir" your-dev-image-name

The -w flag tells cygpath to output a Windows-style path (e.g., D:\my\project\folder instead of /d/my/project/folder).

3. PowerShell-Specific Fix

If you're running the script through PowerShell (which spawns Git Bash), you can skip Git Bash's path conversion entirely by using PowerShell's native $PWD variable. PowerShell's $PWD.Path returns a Windows-style path directly, so you can use it in your command:

docker run -v "$($PWD.Path):/wkDir" your-dev-image-name

Alternatively, set the MSYS_NO_PATHCONV environment variable in PowerShell before running the script:

$env:MSYS_NO_PATHCONV=1; .\your-script.sh

Verify the Fix

Before running the full Docker command, add a test line to your script to check what path is being passed:

echo "Mount path: $PWD:/wkDir"

If you see something like D:/my/project/folder;C:/..., the path conversion is still active. Once you apply the fix, you should see the correct Unix-style path /d/my/project/folder:/wkDir (or the clean Windows-style path if using cygpath).

内容的提问来源于stack exchange,提问作者Sebastian Nemeth

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 08:18:02