8

Is there a way to mount a host directory as a data volume while the host directory path contains a colon? Example

-v /colon:path/test:data

In that case it's treating data as additional option. The /colon:path/test is a correct Unix path.

dan1st
  • 12,568
  • 8
  • 34
  • 67
mordka
  • 392
  • 3
  • 11

1 Answers1

7

Yes. With the --mount option you can specify the source and destination. This option was added to Docker 17.05.0.

--mount type=bind,source=/colon:path/test,destination=/data

Note: You must use absolute pathnames. I'm assuming the destination is /data.

From the docker run manpage:

See also --mount, which is the successor of --tmpfs and --volume. Even though there is no plan to deprecate --volume, usage of --mount is recommended.

Example:

touch foo:bar
docker run --rm --mount type=bind,source=$PWD/foo:bar,destination=/tmp/foo:bar busybox ls /tmp
Ricardo Branco
  • 5,740
  • 1
  • 21
  • 31
  • This is the option for `docker service create` and I'm not using docker swarm mode. – mordka Jul 06 '17 at 10:16
  • This is the option to docker run. Check the manpage in the link above. – Ricardo Branco Jul 06 '17 at 14:24
  • Curious how do you escape `,destination=...` if your path ends with that? (obviously, this is a security issue somewhere) – jonasfj Jul 31 '17 at 23:45
  • @jonasfj Seems like one can do [CSV-escaping](https://github.com/moby/moby/issues/8604#issuecomment-505415519). However, I doubt that this is documentend anywhere ... – langfingaz Jun 21 '22 at 10:01