-
Notifications
You must be signed in to change notification settings - Fork 291
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
Volumes mounted from a Linux WSL instance don't resolve in container #2151
Comments
The work around here is to move your project to somewhere on the Windows file system and run the compose from there, where it works as expected, eg: broken:
working:
|
Issues go stale after 90d of inactivity. Prevent issues from auto-closing with an If this issue is safe to close now please do so. Send feedback to Docker Community Slack channels #docker-for-mac or #docker-for-windows. |
I'm hitting this issue too. I'd like to use docker-run with npx to bootstrap javascript projects. When I use the -v option, nothing is written within WSL. |
There's no clear way to make this work. When you use docker within WSL, you're only running the docker client. The docker daemon is not running within WSL; it's running in a Hyper-V virtual machine, and that virtual machine accesses the Windows filesystem as a network share. WSL can also access the Windows filesystem, so you can move your WSL folder to Alternatively, open up the Hyper-V Manager and use the Quick Create menu to create an Ubuntu virtual machine. Then you can install both the docker daemon and client within the VM, and mounting volumes will work as expected. |
Given that the VM running docker has access to the Windows FS, shouldn't it also be able to access the WSL filesystem that is within said Windows FS? Could it be a case of mapping the Linux path onto the WSL root, eg: |
I don't think that's an intended way to interact with the files. It might work as a kludgy way to get read access to the files, but files you write there won't be recognized by WSL, and you'll still have the problem of not being able to read the unix-style permissions and ownership metadata. If the WSL developers can provide some way to expose the WSL-internal filesystem to the Docker VM, that would get things working. |
Note I was able to get read/write working based on @jamesyale's suggestion, but my Docker Host was using a MobyLinuxVM filesystem (which I think is what most people are using), so the mapping was linux fs to linux fs. See the following Stack Exchange thread for more info: |
/remove-lifecycle stale |
Your symlink will save you some typing, but it doesn't get around the problems I mentioned above. You are not mapping "linux fs to linux fs", you're accessing the Windows filesystem (NTFS) via Samba, inside the MobyLinuxVM. You can read the files in the AppData subfolder that way, but if you try to modify or create files, you're likely to run into problems as described here: https://blogs.msdn.microsoft.com/commandline/2016/11/17/do-not-change-linux-files-using-windows-apps-and-tools/ |
Workaround for files hosted on NTFS (not Linux native): |
how to use Docker with WSL The last thing we need to do is set things up so that volume mounts work. This tripped me up for a while because check this out… When using WSL, Docker for Windows expects you to supply your volume paths in a format that matches this: /c/Users/nick/dev/myapp. But, WSL doesn’t work like that. Instead, it uses the /mnt/c/Users/nick/dev/myapp format. Honestly I think Docker should change their path to use /mnt/c because it’s more clear on what’s going on, but that’s a discussion for another time. |
Ok, so now that WSL has file sharing through Plan 9, can this be made to work? Can Docker for Windows mount paths that start with Could the client translate the paths to that namespace? |
It doesn't seem to work with network share paths (see #2163). However, the upcoming WSL 2 looks like it will solve all these problems. You'll be able to fully run docker within WSL: https://devblogs.microsoft.com/commandline/announcing-wsl-2/ |
Leaving this here for anyone in similar situation: |
This tutorial was helpful to me: |
To get this working I did the following:
|
I guess that WSL 1 can not follow the Linux symbol link as /mnt/c/ to Windows FS C:\ path. So we have to define the docker volume parameter as below docker command in Linux.
I solve this and not upgrade to WSL 2 yet. |
I resolved a similar issue by unblocking 10.0.75.2 in my firewall settings. For example, WSL would not resolve files in a volume mounted directory and creating new files would not reflect in the host. In addition, if I re-run the same command the files I created the first time would still be in the running container but not in the host, weird.
Adding to @timhowes, since the files are shared via network I checked my firewall and noticed 10.0.75.2 was being blocked and unblocking resolved the issue. |
I have this issue too, and I use docker from PowerShell instead. |
I am having the issue with WSL. Mount is not complaining, but it is empty, so it is basically useless. |
For what's it worth, the article here describes a solution that has worked great for me. Note that after creating a config file, your path will change from /mnt/c/... to /c/... This has worked great for me for 6+ months. |
@brad-natelborg Simply changing WSL to mount to /c instead of /mnt/c hasn't allowed me to mount something in my WSL home directory at this point. It just mounts nothing to the location in the container while inspect reports the mount is in place. |
Ran into this issue recently, came up with a more straightforward workaround for mounting my Windows home directory (which I have symlinked to my C:\Users directory) in Docker. I haven't tried it, but
|
This was effectively what worked for me! |
Hi all, thanks for all the workarounds but IMHO this is not something we should be solving in a workaround, it should simply work by default to ensure cross platform consistency. I don't know about you guys but I'm running WSL not because I like to unix while I Windows, but because I'm trying to run something that was written for unix by some unix guy/gal. The whole point is that is should just work the same on both a "real" unix and WSL. Therefore I think this should be fixed in either the docker client or the docker server. Quite possibly in the unix docker client, with some special case handling for WSL. Wherever it makes sense, as long as the same command that works on unix also works in WSL. It's ok to share the C drive in the Docker for Windows settings, although I would prefer if I could share the WSL sandbox instead. But after that it should Just Work™. |
Anyone stumbling here over this issue follow this: Docker Desktop WSL2 Backend and make sure you are running the version 2 of the WSL in PowerShell:
If your Ubuntu VERSION doesn't say 2, you need to update it according to the guide above. After that, you will be able to mount your Linux directory to the Docker Container directly like: |
Can confirm, with WSL2 back-end and WSL integration enabled for the distro in Docker it now works as it should without any hacks or workarounds. 👍 🎉 |
Seems to also be working with Tensorflow set up:
|
With Windows 10 build 19041 and WSL 2 from a windows terminal (cmd / powershell): 🔴 Doesn't work (successful mount but directory is empty):
🔴 Doesn't work (docker exception):
🟢 Works:
🟢 From within a WSL 2 distribution, the following works:
For testing I used I had a lot of confusion here. I hope the examples above help someone to waste less time. |
I don't understand why in Docker Desktop for Windows we should use volumes only from From docker blog:
Also described as Best practices in docker desktop docs:
|
This documentation is for Docker with WSL 2, and the issue addressed here is for Docker with WSL 1. |
I've stumbled here because it happened to me in WSL2. But my issue was due to the Alpine distro, which doesn't have integration enabled to work with the |
I'm also facing this issue. It's fixed when downgrading docker to work with WSL1. |
I have the same issue with WSL2 and Ubuntu20 mircea@DESKTOP-3HUUSU8:~ $ uname -a It works fine if I use the Windows file system, but it is VERY slow. Also confirmed by Windows: For me this problem is a STOPPER for using WSL2. |
Which version of Docker Desktop are you using ? |
I use 2.5.0.1 (49550) |
I'm not 100% sure it's the same issue but, for the life of me I CAN NOT get a container to see the files inside a mounted directory when the directory is bound to a shared network path. Specifically:
|
For anyone else that's running into this issue on WSL 1 (and doesn't yet want to upgrade to WSL 2, for reasons such as microsoft/WSL#4197), you can get around this by using the Example: docker run -v "$(wslpath -w "$(pwd)")":/home/docker ... |
@Rican7 That looks promising! Do you happen to have any more info on how you got it working? I keep getting an error:
EDIT: The path does work if I browse to it on the windows side... |
This answer helped me get past that error, but now I'm back to having an empty folder mounted :[ |
@ionut-arm Same. If I reverse the slashes, then the bindmount is empty:
|
This post helped me get passed this.
|
I have no |
@YouveGotMeowxy check if youre default mount path is something like /mnt |
try docker -v /var:{path} exe |
Several cans of energy drink later, I've found a (hacky) solution to mount any WSL2 DRVFS string inside Docker containers! In PowerShell:
You can then specify volumes as |
Expected behavior
When a valid path, within the Linux filesystem with WSL is specified and mounted into a docker container, the volume should be readable as if one were accessing it on the host system.
Actual behavior
Mounted volumes appear empty.
Information
Steps to reproduce the behavior
/
The above behavior is demonstrated below:
Matching log entries:
It looks like the path being passed up to Windows for the volume mount isn't valid on the host system and needs some kind of transformation - in Windows land, the correct path is something like:
c:/Users/jim/AppData/Local/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/home/jim/test
The text was updated successfully, but these errors were encountered: