How to fix Error response from daemon: invalid volume specification in Docker
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.
Quick fix
Fixes Error response from daemon: invalid volume specification
docker run -v $(pwd)opt/data myimage- Check for missing or misplaced colons
- Use absolute paths for the source
- Verify environment variables are set
- Fix Windows path issues
docker run -v $(pwd)opt/data myimageError response from daemon: invalid volume specification
What this error means
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
Typical symptoms
- Docker run command fails immediately with 'invalid volume specification'
- Docker Compose fails at container creation with volume errors
- Error message shows an incomplete path like ':/var/lib/mysql'
- Volume mount works on one machine but fails on another (especially Windows vs Linux)
- CI/CD pipeline fails when trying to mount volumes
Common causes
- Missing colon separator between source and destination paths
- Using relative paths instead of absolute paths for the source
- Environment variable in the volume path is not set or empty
- Windows path format incompatibility (backslashes, drive letters)
- Extra spaces in the volume specification string
- Missing leading slash on the container destination path
- Conflicting VOLUME declarations in Dockerfile and docker-compose.yml
How to fix "Error response from daemon: invalid volume specification"
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.
Advanced notes
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.
Frequently asked questions
- What does "Error response from daemon: invalid volume specification" mean?
- 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.
- How do I fix "Error response from daemon: invalid volume specification"?
- 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.
- What causes "Error response from daemon: invalid volume specification"?
- Missing colon separator between source and destination paths Using relative paths instead of absolute paths for the source Environment variable in the volume path is not set or empty
- Is the "Error response from daemon: invalid volume specification" error serious?
- It is a low-severity error โ more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- ๐Docker Official Documentation
- ๐ฌStack Overflow: Unable to mount a bind volume(Stack Overflow)
- ๐ฌStack Overflow: Invalid volume specification Ubuntu(Stack Overflow)
- ๐
- ๐