This error occurs when Docker cannot parse the volume mount syntax in your docker run command or docker-compose.yml. Common causes include missing colons, relative paths, unset environment variables, or incorrect path formatting on Windows.
When you mount a volume in Docker using the `-v` or `--mount` flag, Docker expects a specific format: `source:destination` or `source:destination:options`. The "invalid volume specification" error means Docker's parser couldn't understand the volume string you provided. This typically happens when: - The path separator (colon) is missing or in the wrong place - You're using a relative path instead of an absolute path - An environment variable in the path is empty or undefined - On Windows, the drive letter format is incompatible with your Docker setup
The volume specification must have the format source:destination or source:destination:options.
Incorrect:
docker run -v $(pwd)opt/data myimageCorrect:
docker run -v $(pwd):/opt/data myimageEnsure there's a colon (:) separating the host path from the container path.
Docker requires absolute paths for bind mounts. Use $(pwd) or ${PWD} to get the current directory.
Incorrect:
docker run -v ./data:/app/data myimageCorrect:
docker run -v $(pwd)/data:/app/data myimageNote: Use $(pwd) with parentheses, not ${pwd} with curly braces.
If your volume path uses environment variables, ensure they're defined.
Check if variable is set:
echo $MY_DATA_PATHIn docker-compose.yml, provide a default:
volumes:
- ${MY_DATA_PATH:-./default-data}:/app/dataIf the variable is empty, you'll see an error like invalid volume specification: ':/app/data' (notice the empty source).
On Windows with Docker Desktop, path formats can be tricky.
Option 1: Set COMPOSE_CONVERT_WINDOWS_PATHS
set COMPOSE_CONVERT_WINDOWS_PATHS=1Or add to .env file:
COMPOSE_CONVERT_WINDOWS_PATHS=1Option 2: Use forward slashes
volumes:
- /c/Users/myuser/data:/app/dataOption 3: Use Windows-style paths in Git Bash
docker run -v //c/Users/myuser/data:/app/data myimageSpaces in the volume string cause parsing errors.
Incorrect (note the space after colon):
volumes:
- ./data: /app/dataCorrect:
volumes:
- ./data:/app/dataCheck for trailing spaces and spaces around colons.
The container destination path must be absolute (start with /).
Incorrect:
docker run -v $(pwd):/data:app/data myimageCorrect:
docker run -v $(pwd)/data:/app/data myimageVerify Docker volumes work with a basic command:
docker run --rm -v $(pwd):/test alpine ls /testIf this works, the issue is in your specific volume specification. Compare your failing command against this working example.
Named volumes vs bind mounts: Named volumes (like myvolume:/app/data) don't require absolute paths and are generally more portable. Consider using them instead of bind mounts when possible.
Docker Compose path resolution: In docker-compose.yml, relative paths are resolved relative to the directory containing the compose file, not the current working directory.
SELinux considerations: On systems with SELinux (like Fedora/RHEL), you may need to add :z or :Z suffix: -v $(pwd)/data:/app/data:z
Rootless Docker: In rootless Docker mode, some paths may not be accessible. Check that your source path is within your home directory or other allowed locations.
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