Sitecore docker build. Invoke-RemoteScript.ps1 times out

Working on this for over 2 weeks and I’m run out of ideas. Hoping for some1 experienced with dockerized Sitecore. I have a Sitecore Docker (windows container) build and i’m trying to run script on it. Sitecore is built with this tutorial: http://rockpapersitecore.com/2019/10/yet-another-sitecore-docker-series/

Script:

Write-Host "Preparing for DB upgrade"

Import-Module C:\automation\SPE
$session = New-ScriptSession -Username admin -Password b -ConnectionUri http://localhost

$jobId = Invoke-RemoteScript -Session $session -ScriptBlock {
    Install-Package -Path C:\automation\CT_DB_upgrade.zip -InstallMode Merge -MergeMode Merge
} -AsJob

Start-Sleep -s 5
Wait-RemoteScriptSession -Session $session -Id $jobId -Delay 5 -Verbose
Write-Host "CT_DB_upgrade.zip installed"

More over script suppose to update clean DB with tables for our Sitecore connector. Script works fine, tables are added and Sitecore works, but…script times out… After “CT_DB_upgrade.zip installed” it runs for about 2min and times out. Normally on VM script runs for about 0.5/ 1 sec and doesn’t crash.

PS C:\automation> .\install-ct-db.ps1
Preparing for DB upgrade
VERBOSE: Checking the Runspace for the variable id.
VERBOSE: Preparing to invoke the script against the service at url
http://localhost/-/script/script/?sessionId=2ca051be-195d-4f0a-90b7-d084b9246ca3&rawOutput=False&persistentSession=F alse
VERBOSE: Transferring script to server
VERBOSE: Script transfer complete.
VERBOSE: Polling job 55ed096e-16ae-49cd-8d20-4d6a4ec219d1. Status : Available.
VERBOSE: Finished polling job 55ed096e-16ae-49cd-8d20-4d6a4ec219d1.
VERBOSE: Checking the Runspace for the variable id.
VERBOSE: Preparing to invoke the script against the service at url
http://localhost/-/script/script/?sessionId=2ca051be-195d-4f0a-90b7-d084b9246ca3&rawOutput=False&persistentSession=F alse
VERBOSE: Transferring script to server
VERBOSE: Script transfer complete.
CT_DB_upgrade.zip installed
Exception calling "Invoke" with "1" argument(s): "The operation has timed out"
At C:\automation\SPE\ConvertFrom-CliXml.ps1:24 char:9
+         $deserializer = $ctor.Invoke($xr)
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : WebException

Exception calling "InvokeMember" with "5" argument(s): "Non-static method requires a target."
At C:\automation\SPE\ConvertFrom-CliXml.ps1:26 char:16
+ ...      while (!$type.InvokeMember("Done", "InvokeMethod,NonPublic,Insta ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : TargetException

As i understand it crashes at: Stop-ScriptSession -Session $session. I have tried changing different web.config settings, like timeouts, but even if i set timeout after 10min it will timeout anyway after around 2min.

Here is ConvertFrom-CliXml.ps1:

function ConvertFrom-CliXml {
    param(
        [Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)]
        [ValidateNotNullOrEmpty()]
        [String[]]$InputObject
    )
    begin
    {
        $OFS = "`n"
        [String]$xmlString = ""
    }
    process
    {
        $xmlString += $InputObject
    }
    end
    {
    
        $type = [PSObject].Assembly.GetType('System.Management.Automation.Deserializer')
        $ctor = $type.GetConstructor('instance,nonpublic', $null, @([xml.xmlreader]), $null)
        $sr = New-Object System.IO.StringReader $xmlString
        $xr = New-Object System.Xml.XmlTextReader $sr
        $deserializer = $ctor.Invoke($xr)
        $done = $type.GetMethod('Done', [System.Reflection.BindingFlags]'nonpublic,instance')
        while (!$type.InvokeMember("Done", "InvokeMethod,NonPublic,Instance", $null, $deserializer, @()))
        {
            try {
                $type.InvokeMember("Deserialize", "InvokeMethod,NonPublic,Instance", $null, $deserializer, @())
            } catch {
                Write-Warning "Could not deserialize ${string}: $_"
            }
        }
        $xr.Close()
        $sr.Dispose()

    }