Skip to content
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

nerdctl build on Windows cannot use alternative Dockerfile with absolute path #8190

Open
horihel opened this issue Feb 5, 2025 · 7 comments · May be fixed by #8320
Open

nerdctl build on Windows cannot use alternative Dockerfile with absolute path #8190

horihel opened this issue Feb 5, 2025 · 7 comments · May be fixed by #8320
Assignees
Milestone

Comments

@horihel
Copy link

horihel commented Feb 5, 2025

Actual Behavior

Command:
nerdctl build --tag mytag . --file Dockerfile.custom

this always fails with

FATA[0000] lstat /Dockerfile.custom: no such file or directory

so it puts a / in front of whatever you specify - so even with a context of ".", it cannot find the file.

Trying to use an absolute path doesn't work either, as it seems to convert it weirdly:

nerdctl build --tag mytag . --file /d/repos/Dockerfile.cypress

FATA[0000] lstat /D:/repos/Dockerfile.cypress: no such file or directory

Steps to Reproduce

  • Have a repo with a non-standard Dockerfile name (on windows)
  • try to specify your Dockerfile with nerdctl build . -file
  • fail

Result

FATA[0000] lstat /Dockerfile.custom: no such file or directory

Expected Behavior

nerdctl builds with the custom dockerfile just like it successfully builds with a file called "Dockerfile"

Additional Information

No response

Rancher Desktop Version

1.17.1

Rancher Desktop K8s Version

1.32.1

Which container engine are you using?

containerd (nerdctl)

What operating system are you using?

Windows

Operating System / Build Version

Windows 11 23H2 Build 22631.4751

What CPU architecture are you using?

x64

Linux only: what package format did you use to install Rancher Desktop?

None

Windows User Only

FortiVPN is active most of the time.

@bcxpro
Copy link
Contributor

bcxpro commented Feb 21, 2025

I could not reproduce the problem or maybe I am doing something wrong

In powershell Windows 11, Rancher desktop 1.18.0-35-g18b15b35b

PS C:\temp\borrame-issue-8190> cat .\Dockerfile.custom
FROM alpine:latest
RUN apk add --no-cache curl bash
RUN echo "Hi Docker!" > /mensaje.txt
CMD ["bash", "-c", "cat /mensaje.txt && echo 'Executing...' && sleep infinity"]
PS C:\temp\borrame-issue-8190>  nerdctl build --tag mytag . --file Dockerfile.custom
[+] Building 0.6s (7/7)
[+] Building 0.7s (7/7) FINISHED
 => [internal] load build definition from Dockerfile.custom                                                                               0.0s
 => => transferring dockerfile: 217B                                                                                                      0.0s
 => [internal] load metadata for docker.io/library/alpine:latest                                                                          0.5s
 => [internal] load .dockerignore                                                                                                         0.0s
 => => transferring context: 2B                                                                                                           0.0s
 => [1/3] FROM docker.io/library/alpine:latest@sha256:a8560b36e8b8210634f77d9f7f9efd7ffa463e380b75e2e74aff4511df3ef88c                    0.0s
 => => resolve docker.io/library/alpine:latest@sha256:a8560b36e8b8210634f77d9f7f9efd7ffa463e380b75e2e74aff4511df3ef88c                    0.0s
 => CACHED [2/3] RUN apk add --no-cache curl bash                                                                                         0.0s
 => CACHED [3/3] RUN echo "Hi Docker!" > /mensaje.txt                                                                                     0.0s
 => exporting to docker image format                                                                                                      0.1s
 => => exporting layers                                                                                                                   0.0s
 => => exporting manifest sha256:962b3f8445ba3699ea077ab4210459f2c626d24d156508f88db571aa7344d01f                                         0.0s
 => => exporting config sha256:827b928fded9762f1bd8dcaa4ab49eb19d2972566272dc177ccb293a8dbfdf21                                           0.0s
 => => sending tarball                                                                                                                    0.1s
Loaded image: docker.io/library/mytag:latest

@jandubois jandubois added this to the 1.19 milestone Feb 21, 2025
@jandubois
Copy link
Member

I can reproduce the error on Rancher Desktop 1.17.1:

C:\Users\SUSE\tmp>nerdctl build --tag mytag . --file Dockerfile.custom
FATA[0000] lstat /Dockerfile.custom: no such file or directory

C:\Users\SUSE\tmp>nerdctl build --tag mytag . --file c:\Users\SUSE\tmp\Dockerfile.custom
FATA[0000] lstat /c:\Users\SUSE\tmp\Dockerfile.custom: no such file or directory

With 1.18.0 the first command now works, but the second one is still broken, albeit differently:

C:\Users\SUSE\tmp>nerdctl build --tag mytag . --file c:\Users\SUSE\tmp\Dockerfile.custom
FATA[0000] lstat /mnt/c/Users/SUSE/tmp/c:\Users\SUSE\tmp\Dockerfile.custom: no such file or directory

@horihel
Copy link
Author

horihel commented Feb 24, 2025

my specific use case seems to work now with 1.18.0, but @jandubois is right, the absolute path is still broken. Should we leave this issue open for this?

@jandubois
Copy link
Member

Should we leave this issue open for this?

Yes, please leave it open; otherwise we would have to just create another one.

@jandubois jandubois changed the title nerdctl build cannot use alternative Dockerfile nerdctl build on Windows cannot use alternative Dockerfile with absolute path Feb 24, 2025
@mook-as mook-as assigned mook-as and unassigned jandubois Feb 24, 2025
@bcxpro
Copy link
Contributor

bcxpro commented Feb 26, 2025

I posted this comment by mistake on issue #6916. I am now posting it here, where it belongs.

I have not determined exactly where in the code the bug resides, but I have checked what is happening:

When executing

nerdctl  build --tag mytag . --file C:\temp\borrame-issue-8190\Dockerfile.custom`

The nerdctl stub receives these arguments as expected:

builder build --tag mytag . --file C:\temp\borrame-issue-8190\Dockerfile.custom

And transform them them with this result to be executed inside the WSL rancher-desktop distribution:

builder build --tag mytag /mnt/c/temp/rancher-desktop --file C:\temp\borrame-issue-8190\Dockerfile.custom

So the command that is executed in Linux is:

/usr/local/bin/nerdctl --address /run/k3s/containerd/containerd.sock builder build --tag mytag /mnt/c/temp/rancher-desktop --file C:\temp\borrame-issue-8190\Dockerfile.custom

Which results in the error:

FATA[0000] lstat /mnt/c/temp/rancher-desktop/C:\temp\borrame-issue-8190\Dockerfile.custom: no such file or directory

The issue here is that the parser in the stub is not transforming the --file argument at all. The path conversion function is not called at all for the file parameter despite being defined to be processed by the filePathArgHandler.

registerArgHandler("builder build", "--file", argHandlers.filePathArgHandler)

I had not time to go deeper into the issue yet.

The fact that nerdctl.exe builder build --tag mytag . --file Dockerfile.custom works is just good luck, because Dockerfile.custom is not transformed but the resulting command in Linux is valid nerdctl --address /run/k3s/containerd/containerd.sock builder build --tag mytag /mnt/c/temp/rancher-desktop --file Dockerfile.custom

@mook-as
Copy link
Contributor

mook-as commented Feb 27, 2025

C:\Users\SUSE\tmp>nerdctl build --tag mytag . --file c:\Users\SUSE\tmp\Dockerfile.custom

We stopped parsing at the first non-option argument, so --file wasn't processed.

C:\Users\SUSE\tmp>nerdctl build --tag mytag --file c:\Users\SUSE\tmp\Dockerfile.custom .

Would work.

This might need to change, of course, but that means we need to figure out how to deal with args that get passed to the child (e.g. nerdctl run). But that's probably quoted…

@jandubois
Copy link
Member

Just brainstorming here, but how about:

  • process -x and --option args and their optional/required parameters
  • exit on --
  • ignore all other args

Or are you talking about passing a Windows path as a parameter to the container entrypoint command? I don't see how that could ever work. You are supposed to bind directories into the container, and then only reference files relative to the mountpoints. So we should never need to translate the args to the container command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants