New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support relative paths with bind mounts (volumes) #1203
Comments
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
|
Coming from |
Seems like this one got dropped on contributor agreement -- otherwise looks like an easy one to get through. |
Would highly appreciated if there’s any updates regarding this issue. |
@prankymat looks like it failed the automated tests on a rw label |
You can always use replace |
@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 |
Clarified that bind mounts *must* use absolute paths, else they will silently "fail" (have unexpected behavior). References: moby/moby#4830 (comment) docker/cli#1203
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. |
Thanks for opening this ticket. I know we rejected this / similar proposals in the past, but in light of "No is temporary, Yes is forever", perhaps it's time to have another look at this, to see if we are comfortable changing this. Let me try to explain the background behind this (and reasons why it was implemented as it is); Reasons why this (so far) hasn't been supported;First of all, due to the syntax used on the command-line:
The second reason is more "fuzzy", and harder to describe, but may be good to call out explicitly, as there's parts that may need to be looked into (also in general); Bind-mounts are performed on the daemon-side; when creating a container that uses a bind-mount, the So how does that relate to this proposal? Well, it's somewhat orthogonal (bear with me); as mentioned, bind-mounts happen on the daemon side. For example, if I specify For this, reason, we (so far) did not implement logic in the CLI that would suggest otherwise; the CLI parses the argument, and delegates any other validation to the daemon (which can check if the path is valid, and if it exists). The path sent to the daemon must be an absolute path (otherwise it would be "relative to So, is it worth continue to enforce absolute paths, or should we be fine with accepting relative paths?As outlined above, there were good reasons to require absolute paths. Question is now; should we continue to do this? Yes; we still cannot make any assumption about paths on the daemon side. And, yes, this situation still holds for any "remote daemon" where no special handling (as provided by, e.g., Docker Desktop) is in place. However, for "inner loop" / "local" development, the current situation may be causing more confusion than it helps preventing. I expect the "this path must be absolute, because it's a remote path" message to be lost on most users. Looking at some other commands / options that do accept relative paths;
I should note that most of these, with the exception of the Docker Compose case, act on local file-paths, not remote/daemon side, but this distinction is hard to explain to users. Docker Compose originated from being a "developer tool", and always had a stronger preference for "local development" (against a local daemon, not a "remote" deployment). What to do with other "special" paths?Somewhat related to this discussion; handling of How to handle conversion for non-matching platforms?This is even more orthogonal, so just a brief mention; perhaps we need to look if we can make the path-conversion for non-matching platforms "pluggable". Currently, Docker Desktop contains logic to convert (e.g.) a Windows |
From the above, I (personally) think it'd be ok to allow relative paths; with the constraints that relative paths MUST start with a period ( I guess technically we could implement some smart logic to handle relative paths without a leading Let me ping some other people who may have thoughts/opinions on this; @tianon @cpuguy83 @tonistiigi @AkihiroSuda @silvin-lubecki @justincormack @crazy-max |
I'm totally fine with it, compose already does this. |
Docker bind mounts have to use absolute paths, so the docker run command fails when using the relative mounts ./staticfiles and ./mediafiles. This may be supported again (docker/cli#1203)
With this change it is now possible to give a relative path to the --volume and --mount flags. $ docker run --mount type=bind,source=./,target=/test ... $ docker run -v .:/test ... Fixes docker#1203
With this change it is now possible to give a relative path to the --volume and --mount flags. $ docker run --mount type=bind,source=./,target=/test ... $ docker run -v .:/test ... Fixes docker#1203 Signed-off-by: Djordje Lukic <djordje.lukic@docker.com>
With this change it is now possible to give a relative path to the --volume and --mount flags. $ docker run --mount type=bind,source=./,target=/test ... $ docker run -v .:/test ... Fixes docker#1203 Signed-off-by: Djordje Lukic <djordje.lukic@docker.com>
With this change it is now possible to give a relative path to the --volume and --mount flags. $ docker run --mount type=bind,source=./,target=/test ... $ docker run -v .:/test ... Fixes docker#1203 Signed-off-by: Djordje Lukic <djordje.lukic@docker.com>
As previously discussed in moby/moby#4830, it would be useful to be able to bind-mount relative paths like this:
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.The text was updated successfully, but these errors were encountered: