In order for me to write the most bullet-proof scripts as possible that don't break with possible edge cases (no matter how unlikely), how do I escape commas and quotes in Docker bind-mount paths using
Note that Docker docs on bind mounting say everyone is "encouraged to use"
--mount instead of
-v, but the case of
-v, I have a similar question for how to escape
: in paths.
cd /Users/name mkdir te,\"st touch te,\"st/file.txt docker run -it --rm --mount 'type=bind,source=/Users/name/te??st,target=/usr/test' alpine ash
?? needs to be the comma
, and double quote
" from the
te,"st directory created above.
- I tried wrapping the value after
source=in double quotes just to test if it will accept a comma, but get error
bare " in non-quoted-field. This attempt was based on the info-box "Escape values from outer CSV parser" in the Choose the -v or --mount flag section of Docker storage volumes docs. But this field clearly doesn't like double quotes, at all, ever.
- Single quotes, double commas, and backslashes in the volume path don't seem to work, with errors such as
invalid field 'st' must be a key=value pair.
- With this, I am out of guesses. I tried a few random stabs in the dark to see if Docker would do environment variable expansion instead of the shell, but nothing is working.
Is it simply impossible to work with paths or volumes that contain a comma or a double quote in their names? Can I instruct Docker to use environment variables somehow so it does the environment variable expansion instead of the shell?
Or, do I need to use a
compose.yaml file to get around this limitation so I can present the parts/pieces of the mounts in a different encoding/format?