rancher-sandbox / rancher-desktop

Container Management and Kubernetes on the Desktop
https://rancherdesktop.io
Apache License 2.0
6.04k stars 285 forks source link

wsl2 on windows not using current working directory #1431

Open kitsunekyo opened 2 years ago

kitsunekyo commented 2 years ago

Rancher Desktop Version

1.0.0

Rancher Desktop K8s Version

1.23.3

What operating system are you using?

Windows

Operating System / Build Version

Win 10 Pro 10.0.19043 Build 19043

What CPU architecture are you using?

x64

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

No response

Windows User Only

No response

Actual Behavior

I'm trying to replace docker desktop with rancher on wsl2 (ubuntu) windows 10. i can run containers perfectly fine, but when i try to start up my compose project below, it seems like nerdctl does not use the current working directory but /root instead.

Steps to Reproduce

❯ ll
total 192K
-rw-r--r-- 1 aspieslechner aspieslechner 1.1K Feb  1 09:14 LICENSE
-rw-r--r-- 1 aspieslechner aspieslechner 2.5K Feb  1 09:14 README.md
drwxr-xr-x 5 aspieslechner aspieslechner 4.0K Feb  1 09:14 client
-rw-r--r-- 1 aspieslechner aspieslechner  670 Feb  1 09:14 docker-compose.yml
-rw-r--r-- 1 aspieslechner aspieslechner 171K Feb  1 09:14 screenshot.png
drwxr-xr-x 5 aspieslechner aspieslechner 4.0K Feb  1 09:14 server

❯ nerdctl compose up -d
FATA[0000] cannot find a compose YAML, supported file names: [docker-compose.yml docker-compose.yaml compose.yml compose
.yaml] in this directory or any parent

❯ nerdctl compose up -d --file ./docker-compose.yml
FATA[0000] open /root/docker-compose.yml: no such file or directory

Result

nerdctl is not using the current working directory

Expected Behavior

nerdctl should use the current working directory when resolving paths like ./docker-compose.yaml or no path at all.

Additional Information

linked issue on nerdctl https://github.com/containerd/nerdctl/issues/771

evertonlperes commented 2 years ago

@kitsunekyo Thanks for filing the issue.

Just to isolate the container runtime, Have you faced the same issue using moby/dockerd container runtime? If not, could you try and see if you can replicate the same issue?

Thanks

kitsunekyo commented 2 years ago

hey, yes I just switched to moby/dockerd to try it out. i had to manually install docker-compose in my wsl2 ubuntu, as rancher desktop doesnt install it, it seems. but after that it worked perfectly.

i just switched back to containerd again and tried nerdctl again. but with the same result.

❯ nerdctl compose up -d
FATA[0000] cannot find a compose YAML, supported file names: [docker-compose.yml docker-compose.yaml compose.yml compose
.yaml] in this directory or any parent
michaelvdnet commented 2 years ago

Can reproduce.

mn@DELL0349:~$ nerdctl compose up
FATA[0000] cannot find a compose YAML, supported file names: [docker-compose.yml docker-compose.yaml compose.yml compose
.yaml] in this directory or any parent

nerdctl compose up from a windows directory (via /mnt/c) somehow does work.

mn@DELL0349:/mnt/c/lab/compose$ nerdctl compose up
INFO[0000] Ensuring image nginx
INFO[0000] Creating container compose_nginx_1
byjrack commented 2 years ago

I can also reproduce, but using a mac on 1.00 (for the moment)

docker-compose up from the same directory using moby/dockerd no issues, but nerdctl compose up fails with the exact same type of error. I am also getting an error in the return which may be related on how it is trying to path even though that directory is there. It seems to assume the files are in my home and not in cwd.

composetest % ls -l
total 32
-rw-r--r--  1 user  wheel  347 Feb  2 13:07 Dockerfile
-rw-r--r--  1 user  wheel  514 Feb  2 13:10 app.py
-rw-r--r--  1 user  wheel  111 Feb  2 13:02 docker-compose.yml
-rw-r--r--  1 user  wheel   12 Feb  2 12:24 requirements.txt
composetest % pwd
/tmp/composetest
composetest % nerdctl compose -f ./docker-compose.yml up -d
ash: cd: line 1: can't cd to /tmp/composetest: No such file or directory
FATA[0000] open ~/docker-compose.yml: no such file or directory 
composetest % nerdctl compose up -d                        
ash: cd: line 1: can't cd to /tmp/composetest: No such file or directory
FATA[0000] cannot find a compose YAML, supported file names: [docker-compose.yml docker-compose.yaml compose.yml compose.yaml] in this directory or any parent 
TimDumol commented 2 years ago

Also can reproduce, on WSL2 (Windows 11) + Ubuntu 20.04, using nerdctl:

❯ nerdctl compose up
FATA[0000] cannot find a compose YAML, supported file names: [docker-compose.yml docker-compose.yaml compose.yml compose.yaml] in this directory or any parent

❯ ls docker-compose.yml
docker-compose.yml
dairongpeng commented 2 years ago

macOS Monterey 12.2.1 also can reproduce.

 ~/tmp/compose/ nerdctl compose -f ./docker-compose.yaml up -d ash: cd: line 1: can't cd to /Users/dairongpeng/tmp/compose: No such file or directory FATA[0000] open /Users/dairongpeng/docker-compose.yaml: no such file or directory  ~/tmp/compose/ ls docker-compose.yaml

Will there be a fix plan?

vertexclique commented 2 years ago

This issue is still continuing and doesn't allow me to work. Do you have ETA to resolve this issue?

zacanbot commented 2 years ago

The issue still persists with Rancher Desktop 1.3.0

gunamata commented 2 years ago

Just tried with the latest version (1.5.1 as of today) of Rancher Desktop. nerdctl compose --file ./docker-compose.yml and nerdctl compose --file /full/path/to/docker-compose.yml worked for me.

Running just nerdctl compose up still gives below error..

FATA[0000] no configuration file provided: not found

I hope this information helps people looking for a workaround.

jandubois commented 2 years ago

I can confirm that there are issues running nerdctl compose up from inside WSL distros, that we will need to fix.

Everything works correctly from a cmd.exe or Powershell prompt, afaict.

I can also not reproduce this issue an macOS. It does not work from e.g. the /tmp/composetest directory because that isn't mounted into the VM, but it worked for me from directories under my home directory.

If you still have problems with nerdctl compose up on macOS, then please open a separate Github issue for it, as it will have a different root cause. We will use this ticket purely to address the WSL2 issue.

anorm commented 1 year ago

Also seeing something which seems related using --iidfile build flag:

In my Ubuntu WSL distro:

❯ nerdctl build --iidfile foo .
[+] Building 1.1s (6/6) FINISHED
 => [internal] load build definition from Dockerfile                                                                                                                                     0.0s
 => => transferring dockerfile: 49B                                                                                                                                                      0.0s
 => [internal] load .dockerignore                                                                                                                                                        0.0s
 => => transferring context: 2B                                                                                                                                                          0.0s
 => [internal] load metadata for docker.io/library/alpine:latest                                                                                                                         0.9s
 => [auth] library/alpine:pull token for registry-1.docker.io                                                                                                                            0.0s
 => CACHED [1/1] FROM docker.io/library/alpine@sha256:f271e74b17ced29b915d351685fd4644785c6d1559dd1f2d4189a5e851ef753a                                                                   0.0s
 => => resolve docker.io/library/alpine@sha256:f271e74b17ced29b915d351685fd4644785c6d1559dd1f2d4189a5e851ef753a                                                                          0.0s
 => exporting to oci image format                                                                                                                                                        0.1s
 => => exporting layers                                                                                                                                                                  0.0s
 => => exporting manifest sha256:1313f1a0fa18e2b865516b18532e95a202409aae08571f2d457161635352c92d                                                                                        0.0s
 => => exporting config sha256:0ba2b9314db6130620130d7f7c6361d86a13573a4551a7c55a6aeda890424136                                                                                          0.0s
 => => sending tarball                                                                                                                                                                   0.1s
unpacking overlayfs@sha256:1313f1a0fa18e2b865516b18532e95a202409aae08571f2d457161635352c92d (sha256:1313f1a0fa18e2b865516b18532e95a202409aae08571f2d457161635352c92d)...
Loaded image: overlayfs@sha256:1313f1a0fa18e2b865516b18532e95a202409aae08571f2d457161635352c92d

❯ cat foo
cat: foo: No such file or directory

Searching for the foo file, I found it in the rancher-desktop WSL distro. From powershell:

PS C:\> wsl -d rancher-desktop -- cat /root/foo
sha256:1313f1a0fa18e2b865516b18532e95a202409aae08571f2d457161635352c92d
jandubois commented 9 months ago

nerdctl compose up worked for me from WSL now, both with nerdctl and nerdctl.exe.

Leaving this issue open because we still need to repro the --iidfile problem.

jandubois commented 9 months ago

nerdctl compose up worked for me from WSL now, both with nerdctl and nerdctl.exe.

Ok, it depends on the location of the directories. If they are mounted from the host (e.g. /mnt/c/Users/SUSE in my test), then nerdctl.exe works, but when it is a path that only exists in the distro, then it doesn't.

The reason is that nerdctl.exe is a stub that just converts the path names, and the local paths from a different distro are not accessible from inside the rancher-desktop distro, where the real nerdctl is running.

But using the nerdctl binary worked for me every time (with nerdctl version 1.7.3), regardless where the current directory was located.

mook-as commented 9 months ago

Note that nerdctl (outside of the rancher-desktop distribution, so /mnt/c/Program Files/Rancher Desktop/resources/resources/linux/bin/nerdctl or whatever) is also a stub that does some path munging (bind mount shared directories to /mnt/wsl/…) before launching the real nerdctl in the rancher-desktop distro. So if there's issues with --iidfile then there's an error in how we do the bind mounting for it: https://github.com/rancher-sandbox/rancher-desktop/blob/5b0276f7101af7804a36d395d1a60ca33af1fa2a/src/go/nerdctl-stub/parse_args.go#L294

jandubois commented 9 months ago

@mook-as So is there some way the Win32 stub could translate a path like \\wsl.localhost\Ubuntu-22.04\tmp back into something that works inside the rancher-desktop distro?

I don't think this is really necessary, as you should be using nerdctl instead of nerdctl.exe from within WSL, but it would be nice if it also worked via nerdctl.exe when you pass paths generated by wslpath -w ....

For the BATS tests (where I ran into this issue) we can copy the compose files to a host directory, so we still have a way to run the tests against nerdctl.exe.

Anutrix commented 1 month ago

Any updates on this? I still can't run the basic compose command:

❯ ls
backend  docker-compose.yaml  frontend-angular  inner-docker  mongodb  README.md

❯ nerdctl compose up -d
FATA[0000] no configuration file provided: not found

Currently the only way to make it work is to give full path using --file which works but shows following fake error:

2024/10/16 02:25:22 Error parsing arguments: command "compose up" does not support option --file

Without relative paths, it becomes hard to distribute compose projects.