Join us today!

Twincat4026, Runnin...
 
Notifications
Clear all

Twincat4026, Running Inside dockerized Windows11, Access via Mstsc

2 Posts
1 Users
0 Reactions
270 Views
Posts: 17
Topic starter
(@romang)
Eminent Member
Joined: 2 years ago

 

I used to have VirtualBox for different "new" Windows Applications.

With , i assume after a bit of checking, the last updates of my Win11 Machine, 

Virtual Box started to make Problems. The Memory started leaking and eats up to 99%

of the available Memory, then freezes more or less, no matter how much Ram i gave it.

 

In searching for Alternatives, i came across a docker Solution i will present,

perhaps somebody is interested in this.

https://github.com/dockur/windows

Here i found a Windows Image on Docker.

I created a DockerCompose File

services:
  windows:
    image: dockurr/windows
    container_name: win11EpsonRoboter
    environment:
      VERSION: "win11"
      RAM_SIZE: "16G"
      CPU_CORES: "8"
      DISK_SIZE: "71G"
    devices:
      - /dev/kvm
    cap_add:
      - NET_ADMIN
    ports:
      - 127.0.0.1:8007:8006
      - 127.0.0.1:3391:3389/tcp
      - 127.0.0.1:3391:3389/udp
    stop_grace_period: 3m
    restart: on-failure
    volumes:
      - ./data:/storage
      - "~/Documents/projects:/storage/shared"

So i have a ContainerName, exposed Ports and a shared Folder with my Host.

A Powershell Script invokes the docker Container and tries to Remote into it with mstsc.

function Start-Win11EpsonRoboter {
    Write-Host "Script started"
    # Change directory to the location of your compose.yml file
    Set-Location "F:\Docker\win11-Epson"

   $containerName = "win11EpsonRoboter"
   $port = "3391"

    Write-Host "Checking if container is running..."

    # Check if the Docker container is already running
    $isRunning = docker ps --format "{{.Names}}" | Select-String -Pattern $containerName

    if ($isRunning) {
        Write-Host "Container is already running. Connecting via RDP..."
        Start-Process -FilePath "mstsc" -ArgumentList "/v:127.0.0.1:$port", "/f" -NoNewWindow -Wait -PassThru
    }
    else {
        Write-Host "Container is not running. Starting Docker and connecting via RDP..."

        # Start Docker Compose in the background
        docker compose up -d

        # Wait for the Docker container to be ready (adjust sleep time as needed)
        $retryCount = 0
        $maxRetries = 5
        $containerRunning = $false
            while ($retryCount -lt $maxRetries -and -not $containerRunning) {
        Start-Sleep -Seconds 15
        $isRunning = docker ps --format "{{.Names}}" | Select-String -Pattern $containerName
            if ($isRunning) {
                $containerRunning = $true
            }
            $retryCount++
        }

        if ($containerRunning) {
            Write-Host "Container is now running. Connecting via RDP..."
            # Prompt the user for credentials
            Start-Process -FilePath "mstsc" -ArgumentList "/v:127.0.0.1:$port", "/f", "/prompt" 
    }
    else {
            Write-Host "Failed to start the Docker container."
        }
    }

    # Pause execution before closing the window
    Read-Host "Press Enter to exit..."
}

Start-Win11EpsonRoboter

in my Powershell $Profile, i made an Alias

Set-Alias epson 'C:\Users\Grabichler\Documents\projects\Scripts\Win11EpsonRoboter.ps1'

 

So now i can just type

epson

in my Powershell, and the docker starts in the background.

After 15s it tries to mstsc into it.

If the DockerContainer is already running, it mstsc immediatly into it.

 

I find it very convenient and nice way to be able to spin up new Windows Pc and i do not suffer

from performance Issues.

 

Reply
1 Reply
Posts: 17
Topic starter
(@romang)
Eminent Member
Joined: 2 years ago

Now just as a Note(and because i hate the offensive behaviour of windows),

i tried this out on a linux machine.

Because the Windows runs in a Linux Docker (how has to be checked for yourself, because i do not understand it),

i can run it on Linux Docker and mstsc into the Win Machine,

which i find awesome.

So i can have a Linux Computer, which runs different windows container with programs, and in my case

it runs 1000x smoother and faster then VirtualBox.

 

Reply
Share: