简体   繁体   English

当目录名称包含冒号时,无法在 docker 容器中挂载卷

[英]Cannot mount volume in docker container when directory name contains colon

I cannot mount a volume to a docker container when the directory name contains a colon (:)当目录名称包含冒号 (:) 时,我无法将卷安装到 docker 容器

The name of the directory is 2012-08-05-00:16:37 and I prefer not renaming the directory.目录的名称是 2012-08-05-00:16:37,我不想重命名目录。 I tried:我试过:

docker run -it --name test1 \
-v /host_system_path/2012-08-05-00\:16\:37/:/container_path/2012-08-05-00\:16\:37/ 
image_name

I get the error:我收到错误:

docker: Error response from daemon: invalid bind mount spec.See 
'docker run --help'.

If I rename the directory without spaces or only with hyphens, then the directory is mounted into the container without any issues.如果我重命名目录时不带空格或仅带连字符,则该目录将毫无问题地安装到容器中。 Can someone point out how can I solve the problem when the directory contains a colon.有人可以指出当目录包含冒号时如何解决问题。

I am on Ubuntu:16.04 and Docker version 17.06.0-ce.我在 Ubuntu:16.04 和 Docker 版本 17.06.0-ce 上。

It's an open issue with Docker.这是 Docker 的一个悬而未决的问题 But in your case, why would docker run -it --name test1 -v /host_system_path:/container_path image_name not be sufficient?但在你的情况下,为什么docker run -it --name test1 -v /host_system_path:/container_path image_name不够?

Colons are currently not supported when specifying directory mappings via -v , and it seems you cannot escape them either.通过-v指定目录映射时,当前不支持冒号,而且您似乎也无法转义它们。

You need to leverage --mount instead:您需要--mount

docker run ... --mount type=bind,source=/some:colon:file,destination=/container-path ...

In the worst of cases, you may of course alternatively still work around this limitation with a temporary system link ( ln -s ) or rename the target directory temporarily.在最坏的情况下,您当然也可以使用临时系统链接 ( ln -s ) 或临时重命名目标目录来解决此限制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM