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

Improve support for WSL with Docker Desktop and Podman Desktop #2875

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

alban
Copy link
Member

@alban alban commented May 20, 2024

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

The different Linux distributions run in different pidns and mntns under the same Linux kernel. They share a bind mount, typically in /mnt/wsl. And wsl.exe can be used in a WSL distribution to execute a command in another WSL distribution.

image

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]>
Copy link
Member

@eiffel-fl eiffel-fl left a 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.

Comment on lines +284 to +291
dockerExePath, _ := exec.LookPath("docker")
if dockerExePath != "" {
dockerLinkPath, _ := os.Readlink(dockerExePath)
if strings.HasPrefix(dockerLinkPath, "/mnt/wsl/docker-desktop/cli-tools/") {
return true
}
}
return false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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/")

Copy link
Member

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.

Comment on lines +295 to +301
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Copy link
Member

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 {
Copy link
Member

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.

Comment on lines +347 to +349
wslDistroName := pid1Environ["WSL2_DISTRO_NAME"]
if wslDistroName == "" {
wslDistroName = pid1Environ["WSL_DISTRO_NAME"]
Copy link
Member

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
Copy link
Member

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() {
Copy link
Member

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.

@eiffel-fl
Copy link
Member

Also:

  1. A documentation commit would be welcomed.
  2. How does it articulate with Remove systemd workaround #1842?

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

Successfully merging this pull request may close these issues.

None yet

2 participants