| name | docker-git-bash-guide |
| description | Comprehensive Windows Git Bash and MINGW path conversion guide for Docker volume mounts and commands |
Docker on Windows Git Bash / MINGW - Path Conversion Guide
This skill provides comprehensive guidance on handling Docker commands in Git Bash (MINGW) on Windows, with specific focus on volume mount path conversion issues and solutions.
The Path Conversion Problem
When running Docker commands in Git Bash (MINGW) or MSYS2 on Windows, automatic path conversion can cause serious issues with volume mounts and other Docker commands.
What Triggers Automatic Conversion
MSYS/MINGW shells automatically convert arguments that look like Unix paths when calling Windows executables (like docker.exe):
Examples of problematic conversions:
docker run -v /c/Users/project:/app myimage
docker run -v C:\Program Files\Git\c\Users\project:/app myimage
Triggers for path conversion:
- Leading forward slash (
/) in arguments
- Colon-separated path lists (
/foo:/bar)
- Arguments with path components after
- or ,
What's exempt from conversion:
- Arguments containing
= (variable assignments)
- Drive letters (
C:)
- Arguments with
; (already Windows format)
- Arguments starting with
// (network paths/Windows switches)
Shell Detection for Docker Commands
Detecting Git Bash / MINGW Environment
Use these environment variables to detect when path conversion issues may occur:
if [ -n "$MSYSTEM" ]; then
echo "Running in Git Bash/MINGW - path conversion needed"
fi
if [[ "$(uname -s)" == MINGW* ]]; then
echo "Running in MINGW environment"
fi
Solution 1: MSYS_NO_PATHCONV (Recommended for Git Bash)
The most reliable solution for Git Bash on Windows.
Per-Command Usage
Prefix each Docker command with MSYS_NO_PATHCONV=1:
MSYS_NO_PATHCONV=1 docker run -v $(pwd):/app myimage
MSYS_NO_PATHCONV=1 docker run -v /c/Users/project:/app myimage
MSYS_NO_PATHCONV=1 docker run \
-v $(pwd)/data:/data \
-v $(pwd)/config:/etc/config \
myimage
Shell-Level Configuration
Disable path conversion for all Docker commands in your session:
export MSYS_NO_PATHCONV=1
docker run -v $(pwd):/app myimage
Function Wrapper (Automatic per Docker Command)
Create a function wrapper that automatically disables path conversion:
docker() {
(export MSYS_NO_PATHCONV=1; command docker.exe "$@")
}
docker() {
(export MSYS2_ARG_CONV_EXCL='*'; command docker.exe "$@")
}
export -f docker
Solution 2: MSYS2_ARG_CONV_EXCL (MSYS2 Specific)
For MSYS2 environments (not standard Git Bash):
export MSYS2_ARG_CONV_EXCL='*'
export MSYS2_ARG_CONV_EXCL='--dir=;/test'
export MSYS2_ENV_CONV_EXCL='*'
Solution 3: Double Leading Slash
Prefix paths with an extra / to prevent conversion:
docker run -v /c/Users/project:/app myimage
docker run -v //c/Users/project:/app myimage
Advantages:
- No environment variables needed
- Works without wrapper functions
- Portable (extra slash ignored on Linux)
Disadvantages:
- Less readable
- Easy to forget
- Doesn't look like standard Docker syntax
Solution 4: Use $(pwd) with Proper Escaping
Always use lowercase $(pwd) (not $PWD) with proper syntax:
MSYS_NO_PATHCONV=1 docker run -v $(pwd):/app myimage
MSYS_NO_PATHCONV=1 docker run -v $(pwd)/src:/app/src myimage
docker run -v $PWD:/app myimage
docker run -v $(pwd):/app myimage
Docker Volume Mount Best Practices (Git Bash on Windows)
For docker run Commands
docker run -v my-named-volume:/data myimage
MSYS_NO_PATHCONV=1 docker run -v $(pwd):/app myimage
docker run -v //c/Users/project:/app myimage
MSYS_NO_PATHCONV=1 docker run -v $(pwd)/config:/etc/config:ro myimage
MSYS_NO_PATHCONV=1 docker run \
-v $(pwd)/src:/app/src \
-v $(pwd)/data:/app/data \
-v my-named-volume:/var/lib/data \
myimage
For docker-compose.yml Files
Docker Compose files use forward slashes and relative paths - these work correctly in Git Bash:
services:
app:
image: myimage
volumes:
- ./src:/app/src
- ./data:/app/data
- my-data:/var/lib/data
- C:/Users/project:/app
- /c/Users/project:/app
volumes:
my-data:
Important: When running docker compose commands:
docker compose up -d
MSYS_NO_PATHCONV=1 docker compose run -v $(pwd)/extra:/extra app
Complete Examples
Example 1: Simple Application Development
export MSYS_NO_PATHCONV=1
docker run -d \
--name dev-app \
-v $(pwd)/src:/app/src \
-v $(pwd)/public:/app/public \
-p 3000:3000 \
node:20-alpine \
npm run dev
docker logs -f dev-app
Example 2: Database with Data Persistence
docker run -d \
--name postgres-db \
-e POSTGRES_PASSWORD=mypassword \
-v pgdata:/var/lib/postgresql/data \
-p 5432:5432 \
postgres:16-alpine
MSYS_NO_PATHCONV=1 docker run -d \
--name postgres-db \
-e POSTGRES_PASSWORD=mypassword \
-v pgdata:/var/lib/postgresql/data \
-v $(pwd)/init.sql:/docker-entrypoint-initdb.d/init.sql:ro \
-p 5432:5432 \
postgres:16-alpine
Example 3: Full Stack with Docker Compose
cat > docker-compose.yml <<'EOF'
services:
backend:
build: ./backend
volumes:
- ./backend/src:/app/src
- ./data:/app/data
ports:
- "4000:4000"
frontend:
build: ./frontend
volumes:
- ./frontend/src:/app/src
- ./frontend/public:/app/public
ports:
- "3000:3000"
depends_on:
- backend
database:
image: postgres:16-alpine
volumes:
- db-data:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: changeme
volumes:
db-data:
EOF
docker compose up -d
MSYS_NO_PATHCONV=1 docker compose run -v $(pwd)/scripts:/scripts backend bash
Troubleshooting Path Issues
Problem: "No such file or directory" errors
Symptoms:
Error response from daemon: invalid mount config for type "bind":
bind source path does not exist: C:\Program Files\Git\c\Users\project
Diagnosis:
- Path has been incorrectly converted by MINGW
- Notice
C:\Program Files\Git\ prefix added
Solution:
MSYS_NO_PATHCONV=1 docker run -v $(pwd):/app myimage
Problem: Volume appears empty in container
Symptoms:
- Container starts successfully
- But mounted directory is empty
- Files exist on host
Diagnosis:
- Path conversion mangled the source path
- Docker created empty directory instead
Solution:
MSYS_NO_PATHCONV=1 docker run -v $(pwd)/data:/data myimage
docker run -v //c/Users/project/data:/data myimage
docker run -v my-named-volume:/data myimage
Problem: Path with spaces fails
Symptoms:
Error: invalid reference format
Diagnosis:
- Spaces in Windows paths not properly quoted
- Path conversion + spaces = disaster
Solution:
MSYS_NO_PATHCONV=1 docker run -v "$(pwd)":/app myimage
Problem: $PWD not working correctly
Symptoms:
- Using
$PWD variable instead of $(pwd)
- Inconsistent behavior
Solution:
docker run -v $PWD:/app myimage
MSYS_NO_PATHCONV=1 docker run -v $(pwd):/app myimage
Testing Your Configuration
Create a test script to verify Docker volume mounts work correctly:
#!/bin/bash
echo "Testing Docker volume mounts in Git Bash..."
mkdir -p test-mount
echo "Hello from host" > test-mount/test.txt
echo "Test 1: With MSYS_NO_PATHCONV"
MSYS_NO_PATHCONV=1 docker run --rm -v $(pwd)/test-mount:/data alpine cat /data/test.txt
echo "Test 2: With double slash"
docker run --rm -v //$(pwd)/test-mount:/data alpine cat /data/test.txt
echo "Test 3: Without workaround (may fail)"
docker run --rm -v $(pwd)/test-mount:/data alpine cat /data/test.txt
rm -rf test-mount
echo "Testing complete!"
Run it:
chmod +x test-docker-volume.sh
./test-docker-volume.sh
Recommended Configuration
Add to your ~/.bashrc:
export MSYS_NO_PATHCONV=1
docker() {
(export MSYS_NO_PATHCONV=1; command docker.exe "$@")
}
export -f docker
alias docker-compose='MSYS_NO_PATHCONV=1 docker compose'
Platform Detection Script
Use this to automatically detect and configure Docker for Git Bash:
if [ -n "$MSYSTEM" ] || [[ "$(uname -s)" == MINGW* ]]; then
echo "Git Bash detected - enabling Docker path conversion fix"
export MSYS_NO_PATHCONV=1
docker() {
(export MSYS_NO_PATHCONV=1; command docker.exe "$@")
}
export -f docker
fi
Quick Reference
Environment Variables
| Variable | Purpose | Values |
|---|
MSYS_NO_PATHCONV | Disable all path conversion (Git Bash) | 1 to disable |
MSYS2_ARG_CONV_EXCL | Exclude specific arguments (MSYS2) | '*' or patterns |
MSYS2_ENV_CONV_EXCL | Exclude environment variables (MSYS2) | '*' or patterns |
MSYSTEM | MSYS subsystem indicator | MINGW64, MINGW32, MSYS |
Command Patterns
export MSYS_NO_PATHCONV=1
docker run -v $(pwd):/app myimage
MSYS_NO_PATHCONV=1 docker run -v $(pwd):/app myimage
docker run -v //c/Users/project:/app myimage
docker run -v my-data:/data myimage
docker compose up -d
What Works Without Modification
These Docker commands work normally in Git Bash without special handling:
- Named volumes:
-v my-volume:/data
- Network commands:
docker network create
- Image commands:
docker build, docker pull
- Container commands without volumes:
docker run myimage
- Docker Compose with relative paths in YAML
What Needs MSYS_NO_PATHCONV
These commands require path conversion fixes:
- Bind mounts with absolute paths:
-v /c/Users/project:/app
- Bind mounts with $(pwd):
-v $(pwd):/app
- Volume mounts on docker run command line
- Any command with Unix-style absolute paths
Summary
Best Practice for Git Bash on Windows:
- Add to ~/.bashrc:
export MSYS_NO_PATHCONV=1
- Use relative paths in docker-compose.yml:
./src:/app/src
- Use named volumes for data:
my-data:/var/lib/data
- Use $(pwd) with MSYS_NO_PATHCONV for bind mounts:
MSYS_NO_PATHCONV=1 docker run -v $(pwd):/app
This configuration ensures Docker commands work correctly in Git Bash on Windows without path conversion issues.