As previously discussed in https://github.com/moby/moby/issues/4830, it would be useful to be able to bind-mount relative paths like this:
docker run --mount type=bind,source=host-dir,target=/app ...
Note: The original issue suggests
docker run -v host-dir:/app ...which might (probably?) be confused with named volumes so I think it's more likely to expect it from the newer--mountoption.
The two main motivations for this are:
docker run commands, e.g., we have a npm script that currently does something like "start": "docker run -v $PWD:/app ...". It's not easy at all to write a command that would work across Linux, macOS and Windows today.This would be verry helpful! Been looking for this but havent found any good solution....
In my opinion, it is explicit and makes sense to resolve the path as relative path instead of absolute if the bind mount path starts with a ./.
For example:
docker run -v ./data-dump:/app/dump my-image
./ resolves as relative path in docker-compose as well which makes perfect sense and should be supported in docker cli as well imho.
Coming from docker-compose which supports relative paths for volumes I would've expected docker itself to support it.
Seems like this one got dropped on contributor agreement -- otherwise looks like an easy one to get through.
Would highly appreciated if there鈥檚 any updates regarding this issue.
@prankymat looks like it failed the automated tests on a rw label
You can always use replace . by $(pwd) to achieve the same result in the meantime Like so : docker run -v $(pwd)/data-dump:/app/dump my-image
@gpapin You can't, your example won't work in some shells on Windows. See the original post where this is mentioned.
You are right @borekb, this is just a workaround for linux like you mentioned in your original post.
Casual ping that I've addressed this in #1273 which just passed all the tests. Would be more than happy if any moderators could help review it! 馃槃
As workaround for $(pwd), try instead -v %cd%\on\host:/opt/inside/container which should work under windows.
Coming from
docker-composewhich supports relative paths for volumes I would've expected docker itself to support it.
docker-compose does not support this on all OS's. Windows for example is a nightmare for relative mounting regardless of ${PWD} and other what I'd term "hacks"
I don't understand why as OSx is also running in a VM, no matter how lightweight, vagrant and all VM technologies support this. It's crazy that since it's valuation, docker hasn't really innovated much at all.
Most helpful comment
In my opinion, it is explicit and makes sense to resolve the path as relative path instead of absolute if the bind mount path starts with a
./.For example:
./resolves as relative path indocker-composeas well which makes perfect sense and should be supported in docker cli as well imho.