How to fix Error response from daemon: invalid volume specification in Docker

DockerBEGINNERLOWUpdated Dec 1, 2025ยท 243 views

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
  1. Check for missing or misplaced colons
  2. Use absolute paths for the source
  3. Verify environment variables are set
  4. Fix Windows path issues
docker โ€” error
docker run -v $(pwd)opt/data myimage
Error 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

  1. Missing colon separator between source and destination paths
  2. Using relative paths instead of absolute paths for the source
  3. Environment variable in the volume path is not set or empty
  4. Windows path format incompatibility (backslashes, drive letters)
  5. Extra spaces in the volume specification string
  6. Missing leading slash on the container destination path
  7. Conflicting VOLUME declarations in Dockerfile and docker-compose.yml

How to fix "Error response from daemon: invalid volume specification"

1Check for missing or misplaced colons

The volume specification must have the format source:destination or source:destination:options.

Incorrect:

bash
docker run -v $(pwd)opt/data myimage

Correct:

bash
docker run -v $(pwd):/opt/data myimage

Ensure there's a colon (:) separating the host path from the container path.

2Use absolute paths for the source

Docker requires absolute paths for bind mounts. Use $(pwd) or ${PWD} to get the current directory.

Incorrect:

bash
docker run -v ./data:/app/data myimage

Correct:

bash
docker run -v $(pwd)/data:/app/data myimage

Note: Use $(pwd) with parentheses, not ${pwd} with curly braces.

3Verify environment variables are set

If your volume path uses environment variables, ensure they're defined.

Check if variable is set:

bash
echo $MY_DATA_PATH

In docker-compose.yml, provide a default:

yaml
volumes:
  - ${MY_DATA_PATH:-./default-data}:/app/data

If the variable is empty, you'll see an error like invalid volume specification: ':/app/data' (notice the empty source).

4Fix Windows path issues

On Windows with Docker Desktop, path formats can be tricky.

Option 1: Set COMPOSE_CONVERT_WINDOWS_PATHS

bash
set COMPOSE_CONVERT_WINDOWS_PATHS=1

Or add to .env file:

bash
COMPOSE_CONVERT_WINDOWS_PATHS=1

Option 2: Use forward slashes

yaml
volumes:
  - /c/Users/myuser/data:/app/data

Option 3: Use Windows-style paths in Git Bash

bash
docker run -v //c/Users/myuser/data:/app/data myimage
5Remove extra spaces from volume specification

Spaces in the volume string cause parsing errors.

Incorrect (note the space after colon):

yaml
volumes:
  - ./data: /app/data

Correct:

yaml
volumes:
  - ./data:/app/data

Check for trailing spaces and spaces around colons.

6Ensure destination path starts with /

The container destination path must be absolute (start with /).

Incorrect:

bash
docker run -v $(pwd):/data:app/data myimage

Correct:

bash
docker run -v $(pwd)/data:/app/data myimage
7Test with a simple volume mount

Verify Docker volumes work with a basic command:

bash
docker run --rm -v $(pwd):/test alpine ls /test

If 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