mariotoffia / FluentDocker

Use docker, docker-compose local and remote in tests and your .NET core/full framework apps via a FluentAPI
Apache License 2.0
1.33k stars 98 forks source link

Use visual studio 2022 remote testing to test from windows on a WSL2 instance #240

Closed htbmw closed 2 years ago

htbmw commented 2 years ago

I use FluentDocker in my Visual Studio test projects with Docker Desktop for Windows. Recently we switched to WSL and most of the time we use docker on the WSL distro. Is there anything I should configure so that FluentDocker can detect and use docker on WSL?

If docker on WSL is started, but Docker Desktop for Windows is stopped, it fails to detect Docker and therefor the test cannot continue. We would like to completely replace Docker Desktop for Windows with a WSL solution.

If there is already support for docker on WSL, please just let me know what I should configure, otherwise, would it be possible to add support?

mariotoffia commented 2 years ago

Hi @htbmw , I'm using WSL as my main development platfrorm. However, I use docker desktop for windows of which gets mounted into WSL. What you're saying is that you have installed the docker daemon within the WSL environment and do not make use of the docker desktop WSL bridge? I have not tried that but, that would result in how the Linux users of this library uses it (and should work).

The "only" requirements from FluentDocker side is that it may reach at least the `docker binary to function (you may even have many different installation of the docker client if you wish).

If docker on WSL is started, but Docker Desktop for Windows is stopped, it fails to detect Docker and therefor the test cannot continue.

Yes, that's true, you have to start it for your selves - this is out of scope for this little library :)

Makes sense?

Cheers, Mario :)

htbmw commented 2 years ago

Hi Mario,

Thanks for the response.

So I use Visual Studio on Windows, but have set up WSL. I am not running my tests inside WSL. So from outside WSL, I need the tests in Visual Studio (on Windows) to be able to reach docker inside WSL.

Hope this makes more sense what I am trying to do?

I am not 100% sure / confident with exactly how the Docker Desktop for Windows and WSL interact, so I can unfortunately not say confidently that I understand what you mean :)

Regards, Hermo

mariotoffia commented 2 years ago

Hi @htbmw, you may use the docker desktop WSL integration so you can use docker commands inside the WSL. See Docker Desktop Documentation.

image

If you start e.g. bash for the WSL and type docker run hello-world, you will be able to use FluentDocker. If not, please, re-open this issue!

Cheers, Mario :)

htbmw commented 2 years ago

I don't think you fully understand my issue:

I need to get rid of Docker Desktop completely. So I am seeking a solution where the tests in Visual Studio can run on Windows but still reach WSL2 Docker. I am more starting to think that the tests shoulds be run inside WSL2, where it then will have direct access to Docker on wsl2.

But VS does not support execution of tests on WSL (unlike the ability to run and debug .net core applications on WSL).

Due to a change in Docker Desktop's terms and conditions, big companies now need to pay license fees for the use of Docker Compose. I am looking for a solution to be able to still use the Visual Studio on my Windows environment, but use a different Docker (other than Docker Desktop). The only possible alternative I see so far is Docker on WSL2. If it is not going to be possible to achieve what I have asked, then just let me know and I will look for some other options.

mariotoffia commented 2 years ago

Ah now I understand. So you want to use native Linux docker daemon in WSL2?

I think that is something I cannot help with. It may be in a docker or Microsoft forum that can answer that question.

Did a quick google - maybe solves your issue? If so, please report back, I would really like to know! :)

Cheers, Mario :)

htbmw commented 2 years ago

I found the solution to my original problem!

Visual Studio 2022 has a preview feature for Remote Testing. See this link: https://docs.microsoft.com/en-us/visualstudio/test/remote-testing?view=vs-2022

I followed the instructions and created a testEnvironments.json file in the root of my solution with the following json:

{ "version": "1", "environments": [ { "name": "Ubuntu-20.04", "type": "wsl", "wslDistribution": "Ubuntu-20.04" } ]

Visual Studio correctly hooked up with my specified wsl2 distro and discovered and performed all tests successfully and reported the results back in the Visual Studio test explorer.

I am happy with this solution and we can therefor close this.

mariotoffia commented 2 years ago

Thanks, @htbmw, for your contribution!! I'll add this as a recepie.