moby: Cannot mount a volume with '/' in it's name

ErrorCodeVolumeName error is generated: “%s includes invalid characters for a local volume name, only [a-zA-Z0-9][a-zA-Z0-9_.-] are allowed”

Possible root cause: the constant in https://github.com/docker/docker/blob/master/utils/names.go lacks forward slash in regexp.

const RestrictedNameChars = [a-zA-Z0-9][a-zA-Z0-9_.-]

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 18 (7 by maintainers)

Commits related to this issue

Most upvoted comments

I’ve just bitten by this too. Any chance the message could be fixed to reflect the fact that paths are allowed but must be absolute?

Clay, problem is resolved, thank you!

I was violating this requirement: The host-dir can either be an absolute path or a name value.

In my case host volume path was relative. I was actually deceived by the error message:

Error response from daemon: volumes/adms1/app includes invalid characters for a local volume name, only [a-zA-Z0-9][a-zA-Z0-9_.-] are allowed

For those it is not clear, here is a great explanation from #34532 by @thaJeztah https://github.com/moby/moby/issues/34532#issuecomment-322738970 about the invalid characters in the volume name.

ErrorCodeVolumeName error is generated: “%s includes invalid characters for a local volume name, only [a-zA-Z0-9][a-zA-Z0-9_.-] are allowed”

should be

ErrorCodeVolumeName error is generated: “%s includes invalid characters for a local volume name, only [a-zA-Z0-9][a-zA-Z0-9_.-] are allowed. If you intented to pass host-dir use absolute path starting with /”

note that paths like ~/foo or $HOME/foo are expanded to an absolute path (/home/username/foo) by your shell, before invoking docker.

Or in this case, docker-compose. It worked with ${PWD} in the docker-compose.yml file.