-
Notifications
You must be signed in to change notification settings - Fork 187
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
Improve support for WSL with Docker Desktop and Podman Desktop #2875
base: main
Are you sure you want to change the base?
Conversation
The existing --auto-wsl-workaround allowed to run ig in a docker container running in the docker-desktop WSL distribution. This patch adds support for running ig in any WSL distribution and interact with Docker Desktop with the WSL integration. Additionally, the same is done for Podman Desktop. Summary of supported WSL configurations: | ig running on | container runtime | Support | |-----------------------------------------------|---------------------------------------------------|---------| | WSL distribution (without container) | docker installed natively in the WSL distribution | ✅ | | WSL distribution (without container) | podman installed natively in the WSL distribution | ✅ | | WSL distribution (without container) | Docker Desktop with WSL integration | ✅ | | WSL distribution (without container) | Podman Desktop (podman-machine-default) | ✅ | | Docker Desktop container with WSL integration | Docker Desktop with WSL integration | ✅ | | Podman Desktop container | Podman Desktop (podman-machine-default) | ✅ | | - | Docker Desktop with Hyper-V backend | ❌ | Signed-off-by: Alban Crequy <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi!
Do you have an easy way to test it (recipe to build VM or "ready to test" VM)?
Best regards.
dockerExePath, _ := exec.LookPath("docker") | ||
if dockerExePath != "" { | ||
dockerLinkPath, _ := os.Readlink(dockerExePath) | ||
if strings.HasPrefix(dockerLinkPath, "/mnt/wsl/docker-desktop/cli-tools/") { | ||
return true | ||
} | ||
} | ||
return false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dockerExePath, _ := exec.LookPath("docker") | |
if dockerExePath != "" { | |
dockerLinkPath, _ := os.Readlink(dockerExePath) | |
if strings.HasPrefix(dockerLinkPath, "/mnt/wsl/docker-desktop/cli-tools/") { | |
return true | |
} | |
} | |
return false | |
dockerExePath, _ := exec.LookPath("docker") | |
if dockerExePath == "" { | |
return false | |
} | |
dockerLinkPath, _ := os.Readlink(dockerExePath) | |
return strings.HasPrefix(dockerLinkPath, "/mnt/wsl/docker-desktop/cli-tools/") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am also wondering if you should catch the error.
podmanExePath, _ := exec.LookPath("podman") | ||
if podmanExePath != "" { | ||
if _, err := os.Stat("/mnt/wsl/podman-sockets/podman-machine-default/podman-root.sock"); err == nil { | ||
return true | ||
} | ||
} | ||
return false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
podmanExePath, _ := exec.LookPath("podman") | |
if podmanExePath != "" { | |
if _, err := os.Stat("/mnt/wsl/podman-sockets/podman-machine-default/podman-root.sock"); err == nil { | |
return true | |
} | |
} | |
return false | |
podmanExePath, _ := exec.LookPath("podman") | |
if podmanExePath == "" { | |
return false | |
} | |
_, err := os.Stat("/mnt/wsl/podman-sockets/podman-machine-default/podman-root.sock") | |
return err == nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment with regard to catching the errors.
|
||
// getPid1Environ returns the environment variables of the init process in the | ||
// given procfs path. | ||
func getPid1Environ(procPath string) map[string]string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather use Environment
instead of Environ
.
wslDistroName := pid1Environ["WSL2_DISTRO_NAME"] | ||
if wslDistroName == "" { | ||
wslDistroName = pid1Environ["WSL_DISTRO_NAME"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please check the map access with ok
?
return nil | ||
} | ||
|
||
// We can use the workaround based on wsl.exe |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"We cannot use [...]"
return nil | ||
} | ||
|
||
if isPodmanDesktopWSL2() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can factorize code between the isPodmand
and isDocker
cases.
Also:
|
The existing --auto-wsl-workaround allowed to run ig in a docker container running in the docker-desktop WSL distribution.
This patch adds support for running ig in any WSL distribution and interact with Docker Desktop with the WSL integration.
Additionally, the same is done for Podman Desktop.
Summary of supported WSL configurations:
The different Linux distributions run in different pidns and mntns under the same Linux kernel. They share a bind mount, typically in
/mnt/wsl
. Andwsl.exe
can be used in a WSL distribution to execute a command in another WSL distribution.