This error occurs when you specify a relative path (like . or ./app) for a volume mount instead of an absolute path. Docker requires the full, complete path starting from the root directory for bind mounts to work correctly.
When Docker encounters "invalid mount config: mount path must be absolute," it means the path you provided for a volume or bind mount doesn't start from the filesystem root. Docker's volume mounting syntax requires absolute paths on both the host and container sides. An absolute path starts with a forward slash (`/`) on Linux/macOS or a drive letter like `C:\` on Windows. Relative paths like `.`, `./data`, or `../config` are not valid mount sources because Docker cannot reliably resolve them to a specific location. This error commonly occurs when: - Using `.` or `./` to refer to the current directory - Using `~` for the home directory (which some shells expand, but Docker doesn't) - Path conversion issues in Windows terminals (especially Git Bash/MinGW) - Copying commands from documentation that use relative paths as examples
First, locate the volume mount causing the error. Look for -v or --mount flags in your docker command, or volumes: in docker-compose.yml:
# Common problematic patterns:
docker run -v ./app:/app myimage # Relative path with ./
docker run -v .:/code myimage # Single dot
docker run -v ~/data:/data myimage # Tilde for home
docker run -v data:/app myimage # Missing leading slashThe path before the colon (:) is the host path that must be absolute.
Replace relative paths with full absolute paths. Use these methods to get the absolute path:
On Linux/macOS:
# Get current directory as absolute path
pwd
# Example output: /home/user/project
# Use in docker command
docker run -v /home/user/project/app:/app myimage
# Or use command substitution
docker run -v "$(pwd)/app:/app" myimageOn Windows (PowerShell):
# Get current directory
Get-Location
# Example: C:\Users\user\project
# Use in docker command
docker run -v C:\Users\user\project\app:/app myimage
# Or use variable
docker run -v "${PWD}/app:/app" myimageGit Bash (MinGW) automatically converts Unix-style paths to Windows paths, which can break Docker commands. Use one of these solutions:
Solution 1: Add extra leading slash
# Instead of:
docker run -v $(pwd):/app myimage
# Use double leading slash:
docker run -v /$(pwd):/app myimage
# For explicit paths:
docker run -v //c/Users/user/project:/app myimageSolution 2: Disable path conversion
# Set environment variable for single command
MSYS_NO_PATHCONV=1 docker run -v $(pwd):/app myimage
# Or export for entire session
export MSYS_NO_PATHCONV=1
docker run -v $(pwd):/app myimageSolution 3: Use Windows-native terminal
Run Docker commands from PowerShell or Command Prompt instead of Git Bash.
Docker doesn't expand the tilde (~) character. Replace it with the actual home directory path:
On Linux/macOS:
# Instead of:
docker run -v ~/data:/data myimage
# Use:
docker run -v /home/username/data:/data myimage
# Or use $HOME variable:
docker run -v "$HOME/data:/data" myimage
# Or use command substitution:
docker run -v "$(echo ~)/data:/data" myimageOn Windows:
# Instead of ~ use full path:
docker run -v C:\Users\username\data:/data myimage
# Or use environment variable:
docker run -v "$env:USERPROFILE\data:/data" myimageIn docker-compose.yml, relative paths are resolved from the compose file's directory. However, you may still need absolute paths in some cases:
Using relative paths (usually works):
version: '3.8'
services:
app:
image: myimage
volumes:
- ./app:/app # Relative to docker-compose.yml location
- ./data:/dataIf relative paths fail, use absolute:
version: '3.8'
services:
app:
image: myimage
volumes:
- /home/user/project/app:/app
- /home/user/project/data:/dataUsing environment variables:
services:
app:
volumes:
- ${PWD}/app:/app
- ${PROJECT_ROOT}/data:/dataThen run with:
PROJECT_ROOT=/home/user/project docker-compose upAfter fixing the path format, verify the directory exists:
# Check if path exists
ls -la /home/user/project/app
# Create if needed
mkdir -p /home/user/project/app
# Test the mount
docker run --rm -v /home/user/project/app:/app alpine ls /appIf the directory doesn't exist, Docker will create it as root on Linux, which may cause permission issues later. It's better to create it beforehand with appropriate permissions.
If you don't need to access files from the host, consider using named volumes instead of bind mounts. Named volumes don't require absolute paths:
# Create a named volume
docker volume create mydata
# Use it in a container
docker run -v mydata:/app/data myimageIn docker-compose.yml:
version: '3.8'
services:
app:
image: myimage
volumes:
- mydata:/app/data
volumes:
mydata:Named volumes are managed by Docker and don't have path format issues across different operating systems.
Understanding the path syntax:
The volume mount syntax is -v host_path:container_path[:options]. Both paths should be absolute:
- Host path: Where data lives on your machine (must be absolute)
- Container path: Where data appears inside the container (always absolute, Unix-style)
Windows path formats:
Windows supports multiple path formats with Docker:
- Native: C:\Users\user\data
- Forward slashes: C:/Users/user/data
- Unix-style (Docker Toolbox): /c/Users/user/data
- WSL paths: /mnt/c/Users/user/data
Docker Toolbox vs Docker Desktop:
Docker Toolbox (legacy) runs Docker in a VirtualBox VM, requiring paths to be shared through VirtualBox first. Docker Desktop on Windows uses WSL2 or Hyper-V and handles paths more seamlessly.
COMPOSE_CONVERT_WINDOWS_PATHS:
Set this environment variable to handle Windows paths in docker-compose:
export COMPOSE_CONVERT_WINDOWS_PATHS=1
docker-compose upCI/CD considerations:
In CI/CD pipelines, use environment variables or workspace paths provided by the CI system:
# GitHub Actions example
docker run -v ${{ github.workspace }}:/app myimageSecurity note:
Mounting the current directory ($(pwd)) in development is convenient but avoid mounting sensitive directories in production. Use specific paths and consider read-only mounts (:ro) when the container doesn't need write access.
dockerfile parse error line 5: unknown instruction: RRUN
How to fix 'unknown instruction' Dockerfile parse error in Docker
Error response from daemon: manifest for nginx:nonexistent not found: manifest unknown: manifest unknown
How to fix 'manifest for image:tag not found' in Docker
Error response from daemon: invalid reference format: repository name must be lowercase
How to fix 'repository name must be lowercase' in Docker
Error response from daemon: No such image
How to fix 'No such image' in Docker
Error response from daemon: Container is not running
How to fix 'Container is not running' when using docker exec