nerdctl icon indicating copy to clipboard operation
nerdctl copied to clipboard

Unable to mount volumes or bind mount on Windows

Open MikeTheSnowman opened this issue 3 years ago • 15 comments

Issue:

When using nerdctl + containerd on Windows, I am unable to mount volumes or bind mount to a new windows container. I've tried using the following command with no success:

PS C:\Users\Administrator\nerdctl\_output> nerdctl.exe --debug-full run -d -v C:\bind_volumes\v1:c:\src hello-world:nanoserver-1809
time="2022-01-30T02:04:37-08:00" level=debug msg="verification process skipped"
time="2022-01-30T02:04:37-08:00" level=debug msg="Calling proc (1)" spanID=7599fa456674789d traceID=6d976231e769a37073cadb49b4a21362
time="2022-01-30T02:04:37-08:00" level=debug msg="Calling proc (2)" spanID=7599fa456674789d traceID=6d976231e769a37073cadb49b4a21362
time="2022-01-30T02:04:37-08:00" level=fatal msg="failed to parse \"C:\\\\bind_volumes\\\\v1:c:\\\\src\""

I've also tried experimenting with the the -v option, by trying various ways of single/double quoting an escaping special characters, but again I did not have any success.

Code Investigation:

Now, I do not know how to program in Go (so please excuse me if I'm totally wrong here). But starting at line 56 in mountutil.go, it looks like that whole switch statement is really only designed to handle Linux paths. I say this because on line 56, the value passed to -v is being split on the ":" character and the switch statement doesn't look like it would be able to handle bind mount (eg: -v c:\hostDir:c:\guestDir) or just mounting volumes to a windows container (eg: -v vol1:c:\guestDir).

Also, line 56's parent function (generateMountOpts), returns back up to run_mount.go on line 195. Just a few lines below that on line 203, it looks like the SecureJoin may encounter issues if a full windows path containing a colon character were to be joined with tempDir on that line.

That's what I've been able to observe to the best of my ability. If I'm overthinking or if I've made some very obvious mistake when trying to use the -v option, please let me know.

Thanks!

My Environment:

  • OS: Windows Server 2019
  • OS Version: 1809 (OS Build 17763.1282)
  • CPU arch: Intel x86-64
  • nerdctl version: v0.16.0
  • containerd version v1.5.9
  • Other information:
    • Is the Windows Container feature enabled: Yes

MikeTheSnowman avatar Jan 30 '22 10:01 MikeTheSnowman

I would like to make a PR to fix this

Zheaoli avatar Feb 08 '22 09:02 Zheaoli

I would like to make a PR to fix this

Thanks for taking a look!

jsturtevant avatar Feb 08 '22 16:02 jsturtevant

Use instead: -v /bind_volumes/v1:/src For me in Windows it works using Linux paths style.

textminer avatar Feb 11 '22 13:02 textminer

for reference docker does work with the c:\:

docker run -it -v c:\temp:C:\temp k8s.gcr.io/e2e-test-images/busybox:1.29-2 cmd
Microsoft Windows [Version 10.0.17763.2114]                                                                                                                                                    (c) 2018 Microsoft Corporation. All rights reserved.

C:\>dir
 Volume in drive C has no label.
 Volume Serial Number is 5C49-4D09

 Directory of C:\

08/25/2021  05:31 AM    <DIR>          bin
08/25/2021  05:31 AM    <DIR>          curl
08/25/2021  05:31 AM    <DIR>          dig
08/05/2021  11:08 AM             5,510 License.txt
08/25/2021  05:31 AM    <DIR>          Program Files
03/09/2022  08:48 AM    <DIR>          temp
08/25/2021  05:31 AM    <DIR>          tmp
03/09/2022  08:51 AM    <DIR>          Users
03/09/2022  08:51 AM    <DIR>          Windows
               1 File(s)          5,510 bytes
               8 Dir(s)  21,294,342,144 bytes free

C:\>cd temp

C:\temp>

jsturtevant avatar Mar 09 '22 16:03 jsturtevant

I am unable to mount volumes or bind mount to a new windows container. I've tried using the following command with no success:

Hey @textminer, if I use this approach, do you have a recommendation on how to target different windows drive letters? For example, if I wanted to bind-mount "f:\foo\bar", how would I accomplish this using nerdctl?

MikeTheSnowman avatar Mar 15 '22 07:03 MikeTheSnowman

@wtfacoconut There is a bug in containerd for different drive letters in Windows: https://github.com/containerd/containerd/issues/6589. Once that is fixed and this parsing error here is fixed, we would be able to support the other driver letters

jsturtevant avatar Mar 16 '22 00:03 jsturtevant

@wtfacoconut There is a bug in containerd for different drive letters in Windows: https://github.com/containerd/containerd/issues/6589. Once that is fixed and this parsing error here is fixed, we would be able to support the other driver letters

Understood. Thanks for the info.

MikeTheSnowman avatar Mar 16 '22 01:03 MikeTheSnowman

@wtfacoconut There is a bug in containerd for different drive letters in Windows: containerd/containerd#6589. Once that is fixed and this parsing error here is fixed, we would be able to support the other driver letters

Looks like containerd/containerd#6589 fixed by containerd v1.6.6 (PR https://github.com/containerd/containerd/pull/6651)

junnplus avatar Jun 25 '22 09:06 junnplus

PS C:\> containerd.exe -v
containerd github.com/containerd/containerd v1.6.6 10c12954828e7c7c9b6e0ea9b0c02b01407d3ae1

PS C:\> nerdctl.exe -v
nerdctl version 0.21.0

Get "failed to parse" error message:

PS C:\> nerdctl.exe --debug-full run -it -v C:\tools\:c:\tools --rm --name test mcr.microsoft.com/windows/nanoserver:ltsc2022
time="2022-07-22T08:55:21Z" level=debug msg="verification process skipped"
time="2022-07-22T08:55:21Z" level=debug msg="Calling proc (1)" spanID=0fbc95fd368421cb traceID=751b7e5859dbdbba7510ddbf9c44f373
time="2022-07-22T08:55:21Z" level=debug msg="Calling proc (2)" spanID=0fbc95fd368421cb traceID=751b7e5859dbdbba7510ddbf9c44f373
time="2022-07-22T08:55:21Z" level=fatal msg="failed to parse \"C:\\\\tools\\\\:c:\\\\tools\""

kkbruce avatar Jul 22 '22 08:07 kkbruce

@kkbruce this won't work, there is a patch in progress at https://github.com/containerd/nerdctl/pull/924

work around is to use /path/ without the drive : https://github.com/containerd/nerdctl/issues/759#issuecomment-1036215481

jsturtevant avatar Jul 22 '22 16:07 jsturtevant

@jsturtevant @textminer

I've been trying for a long time and can't come up with the alternatives you mentioned. Can you provide a complete run description of the -v or -mount parameters?

Local c:\\data folder:

PS C:\> dir .\data\

    Directory: C:\data

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----         7/25/2022   3:36 PM              8 test.txt

Test mount function:

PS D:\> nerdctl.exe run -it --rm -v "/data/:c:\Windows\Temp" mcr.microsoft.com/windows/servercore:ltsc2022
time="2022-07-25T15:49:09+08:00" level=warning msg="expected an absolute path, got a relative path \"/data/\" (allowed for nerdctl, but disallowed for Docker, so unrecommended)"
time="2022-07-25T15:49:09+08:00" level=fatal msg="expected an absolute path, got \"c\""

PS D:\> nerdctl.exe run -it --rm -v "/data/:/Windows/Temp" mcr.microsoft.com/windows/servercore:ltsc2022
time="2022-07-25T15:49:23+08:00" level=warning msg="expected an absolute path, got a relative path \"/data/\" (allowed for nerdctl, but disallowed for Docker, so unrecommended)"
time="2022-07-25T15:49:23+08:00" level=fatal msg="expected an absolute path, got \"/Windows/Temp\""

kkbruce avatar Jul 25 '22 08:07 kkbruce

I am running nerdctl from gitbash on Windows machine and this command is working for me: nerdctl run -v c\:/folder/anotherfolder:/build/somefolder <image_id> ls build/somefolder

ablackrain avatar Apr 26 '23 14:04 ablackrain

Any progress on this? I've tried a lot of combinations of path specification. Nothing works.

jfb0101 avatar Aug 18 '23 20:08 jfb0101

Same problem there. I tried in all possible ways but I have to deal with Docker CE yet. Any ETA regarding this issue, or which version will have a fix available?

Thanks!

Suzamax avatar Oct 11 '23 06:10 Suzamax

Any updates ? Thanks

Choquito29 avatar Nov 01 '23 10:11 Choquito29