-
Notifications
You must be signed in to change notification settings - Fork 18.7k
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
docker -v /host:/container relative paths (volume relative path) #4830
Comments
@blast-hardcheese There is no warranty that your client is on the same host as your server.
|
Ah, very good point! There is no warning. Should non-absolute paths error out by default, only allowed via an option? In my use-case, filling / with empty directories is not very useful, but I can see how it could be useful in controlled circumstances.
|
+1 for relative host paths being a hard error |
As of 1.9.1, build a34a1d5, docker doesn't complain about relative paths and fail fast. Instead it merrily chugs along and gives wrong results. I don't mind diving in to make it fail fast if others agree it would be better. |
@ijt This is because of named volumes... the syntax has just gotten to overloaded and on top of that auto-creation of volumes makes it impossible to know user intent. |
Okay, sounds good. |
Ahh, late to the party, I searched, saw this, and realized if you want a "relative" path you can do this:
If you're running from a shell script, this is fine, you're going to be running it from somewhere, great for local development when you're standing up a few images and want to keep those folders handy. |
@jayproulx it's too bad that approach does not work with Windows. But we can use |
same problem |
In related issue we have solution
i.e. use docker run -it --rm --name py-script-container -v "$PWD":/usr/src/myapp -w /usr/src/myapp/esp8266/tools python:alpine python get.py instead of docker run -it --rm --name py-script-container -v "$PWD":/usr/src/myapp -w /usr/src/myapp python:alpine python esp8266/tools/get.py |
I know this is old, but I just made this mistake on Mac and I don't know where I've created a directory on the host (Mac). I ran
Where is |
@farshidz It's a named volume that exists in the docker VM. |
@farshidz There are 2 types of volumes in Docker: "bind mount" and "managed".
|
Is there an open issue for relative volume mounts, or is it a "won't fix"? If everyone on our team was on Linux or macOS, Is there a technical reason why |
@borekb You can use relative paths for volumes, if you go with For example a trivial
Bring it up with The folder where |
@tkalfigo thanks, I am aware that docker-compose supports relative paths so I'm not sure why Docker engine doesn't. |
This is a client issue (github.com/docker/cli). |
Aha, I re-read the previous more carefully and this is important:
Now I understand better why supporting relative paths in |
|
In stable or some future release? Cannot find a mention of it in the docs. Would be a life saver :) |
https://docs.docker.com/storage/bind-mounts/ It's been around for a few releases. |
Thanks for the pointer. I'm still confused though: the first paragraph on that page mentions that relative paths should be supported:
That doesn't seem to be the case though:
Am I invoking it correctly? Also, does the "response from daemon" mean that it's the Docker engine that rejects the relative path so it's not just a CLI issue? |
Yes. The docs are definitely incorrect in that regard. |
Thanks for confirming. Is this issue still valid then and could be re-opened? Making absolute paths working cross-platform is not easy at all, for example, some npm scripts we have do |
It definitely doesn't make sense in this repo as it's totally a client issue. The docker CLI is in github.com/docker/cli. I can see good reason to support relative paths if for nothing else than to have a compatible syntax with compose... |
Thanks, I've created docker/cli#1203. |
This commit fixes a series of issues in the getting started guide: - Avoid using relative paths for docker volumes. Use `pwd` instead: moby/moby#4830 (comment) - Fix indentation in prometheus config - Fix otcollector example - Missing span processor - Remove sampling_initial and sampling_thereafter keys in config
This commit fixes a series of issues in the getting started guide: - Avoid using relative paths for docker volumes. Use `pwd` instead: moby/moby#4830 (comment) - Fix indentation in prometheus config - Fix otcollector example - Missing span processor - Remove sampling_initial and sampling_thereafter keys in config
This commit fixes a series of issues in the getting started guide: - Avoid using relative paths for docker volumes. Use `pwd` instead: moby/moby#4830 (comment) - Fix indentation in prometheus config - Fix otcollector example - Missing span processor - Remove sampling_initial and sampling_thereafter keys in config
So... is Docker refusing to support relative paths on some philosophical basis, or did I misunderstand this thread? How am I supposed to write documentation for running a Docker VM, without relative paths? Do I have to force every developer to clone their source code to the same location on every machine, just so that my project's setup instructions work with these absolute paths? Seems pretty crazy. |
@Pointotech Also, that is correct we cannot support relative paths from the CLI with But also, paths would be relative to the daemon not the client. |
In Windows PowerShell the following command works as mounting relative paths: docker run -v ${pwd}:/var/lib/mydata |
Clarified that bind mounts *must* use absolute paths, else they will silently "fail" (have unexpected behavior). References: moby/moby#4830 (comment) docker/cli#1203
When
volume
is specified via a command-line argument, relative paths should be prepended with the current working directory, vs the directory the daemon was started in.docker run -v data:/var/lib/mydata ...
creates and mounts/data
.The text was updated successfully, but these errors were encountered: