windows icon indicating copy to clipboard operation
windows copied to clipboard

[Question]: How can I run dotnet test inside the Docker Windows Container without using the web browser?

Open TesterEric opened this issue 9 months ago • 7 comments

Is your question not already answered in the FAQ?

  • [x] I made sure the question is not listed in the FAQ.

Is this a general question and not a technical issue?

  • [x] I am sure my question is not about a technical issue.

Question

How can I run a .NET test inside the Windows environment without using the web browser?

I want to use a Dockurr\windows image, because my tests have a dependency with Windows dll's and can therefore not run in a Linux environment. I was able to install the .NET SDK via the dotnet install scripting (https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-install-script) and the install.bat file suggested in the "How do I run a script after installation" section of https://hub.docker.com/r/dockurr/windows.

I tried docker exec windows dotnet test but it fails complaining "OCI runtime exec failed: exec failed: unable to start container process: exec: "dotnet": executable file not found in $PATH: unknown". It seems it wants to execute the tests in the Linux environment instead of Windows. Running the tests must be part of an automated build process, so manually starting the tests from the web browser (localhost:8006) is no option.

Hopefully someone can help so that I can continue?

compose.yml

services:
  windows:
    image: dockurr/windows
    container_name: windows
    environment:
      VERSION: "11"
    devices:
      - /dev/kvm
      - /dev/net/tun
    cap_add:
      - NET_ADMIN
    ports:
      - 8006:8006
      - 3389:3389/tcp
      - 3389:3389/udp
    volumes:
      - ./win11x64.iso:/custom.iso
      - ./windows:/storage
      - ./install:/oem
    
    restart: always
stop_grace_period: 2m

install.bat (install .NET SDK and set path)

cd c:\oem

echo Install .NET SDK in c:\dotnet
Powershell.exe -ExecutionPolicy Unrestricted -File ./dotnet-install.ps1 -InstallDir c:\dotnet

echo Add c:\dotnet to Path environment variable (persistent)
Powershell.exe [Environment]::SetEnvironmentVariable('Path', $env:Path + ';c:\dotnet', 'Machine')

TesterEric avatar Apr 02 '25 08:04 TesterEric

Its correct that exec is executed in the Linux container. See here https://github.com/dockur/windows/issues/412 for an example using RemoteApp to execute something inside Windows via the commandline in Linux.

kroese avatar Apr 02 '25 10:04 kroese

@kroese , first if all thank you for your the reply, but the solution you mean is not completely clear to me.

  • Should I install xfreerdp in the linux distro inside the Docker container and run xfreerdp with docker exec to be able to run "something" on Windows?
  • If not, how can I use your proposed solution?

When I try to install xfreerdp in the docker container (based on dockurr\windows) with apt-get install it fails because it cannot find a package with that name.

TesterEric avatar Apr 02 '25 13:04 TesterEric

No you install it on your host system. And I believe the package is called freerdp2

kroese avatar Apr 02 '25 15:04 kroese

@kroeze, it seems there is no installer available for freerdp2 (only sources). Does anyone have experience on how to install and use freerdp on a Windows host system to connect to dockurr\windows container to be able to execute an executable running on Windows (in the container)?

TesterEric avatar Apr 03 '25 12:04 TesterEric

@kroeze, I am using sdl2-freerdp.exe (from https://ci.freerdp.com/job/freerdp-nightly-windows/arch=win64,label=vs2017/), but with the example of #412 I am not able to connect. Which IP address should I use? I am now trying with /v:localhost:3389

TesterEric avatar Apr 03 '25 14:04 TesterEric

If your host system is Windows, you dont need FreeRDP at all. I assumed it was Linux.

In that case it might be easier to just setup a Remote Powershell connection to the machine, see https://learn.microsoft.com/en-us/powershell/scripting/security/remoting/running-remote-commands?view=powershell-7.5 for example.

kroese avatar Apr 03 '25 14:04 kroese

@kroese , thanks, it is working now with the PS Invoke-Command and using the WinRM port.

TesterEric avatar Apr 17 '25 04:04 TesterEric

@TesterEric, could you share the steps you took to configure WinRM?

mhagnumdw avatar Dec 03 '25 18:12 mhagnumdw

@mhagnumdw , winrm does not work on Linux meaning that we could not use winrm port 5985 to connect with Windows. We managed to get ssh working, but by default the ssh port is not exposed by the Docker image. You have to configure it as USER mode networking and add port 22. With port forwarding you access ssh port 22 and execute commands inside the Windows environment on Docker.


      containers:
      - name: my-container
        image: dockurr/windows:5.06
        
        env:
        - name: DISK_SIZE
          value: "64G"
        - name: USER_PORTS
          value: "22"
        - name: NETWORK
          value: "user"

TesterEric avatar Dec 04 '25 05:12 TesterEric

@TesterEric , I managed to get it working like this:

install.bat

:: -----------------------------------------------------------------------------
:: Enable WinRM
:: -----------------------------------------------------------------------------
echo [INFO] Enabling WinRM...
powershell -Command "Get-NetConnectionProfile | Set-NetConnectionProfile -NetworkCategory Private"
call winrm quickconfig -q -transport:http
:: Waiting for the WinRM service to fully start (but it wasn't necessary).
@REM timeout /t 5 /nobreak
call winrm set winrm/config/service/auth @{Basic="true"}
call winrm set winrm/config/service @{AllowUnencrypted="true"}
echo [INFO] WinRM enabled successfully.
echo.

No host:

pip install pywinrm
#!/usr/bin/env python3

import winrm

session = winrm.Session('http://127.0.0.1:5985/wsman', auth=('Docker', 'admin'))
result = session.run_cmd('cmd.exe', ['/c', 'echo Hello World from Windows via WinRM!'])
print(result.std_out.decode())

mhagnumdw avatar Dec 04 '25 12:12 mhagnumdw