microsoft / navcontainerhelper

Official Microsoft repository for BcContainerHelper, a PowerShell module, which makes it easier to work with Business Central Containers on Docker.
MIT License
369 stars 239 forks source link

`Enter-BCContainer` is broken on PS7 #3537

Open hemisphera opened 2 months ago

hemisphera commented 2 months ago

Describe the issue Enter-BCContainer seems to be broken on PS7. Whenever I try to enter a BC container on PS7 I get the error that I have logged down below in the full output of the scripts.

I started using the alternative Open-BCContainer ever since, which works fine. But there are a few quirks here that I think are worth reporting and resolving.

  1. I don't really get the difference between Enter-BCContainer and Open-BCContainer. Aside from the fact that the latter opens a new terminal window and seems to be a little less "integrated" (colorcoding, syntax a.s.o.). And of course: the fact that one works for PS7 and the other doesn't. So my question is: why keep both? Why not deprecate one and just keep the other?
  2. After finishing a New-BCContainer call, you conveniently output a list of cmdlets that are useful now. One of those keeps being Enter-BCContainer, event though - as reported above - it does no longer work on PS7.
  3. Another quirk i noticed is: Enter-BCContainer is one of those (many) cmdlets where the name of the container is case sensitive. On a whole lot of other cmdlets it is not. This is not strictly related to Enter-BCContainer, but rather a general problem i noticed. I think it would be worth streamlining this across the entirety of BCCH.

Scripts used to create container and cause the issue

New-BcContainer `
  -containerName "BC24-RTM" `
  -accept_eula `
  -artifactUrl = https://bcartifacts-exdbf9fwegejdqak.b02.azurefd.net/onprem/24.0.16410.18056/w1 `
  -updateHosts `
  -dns "8.8.8.8" `
  -shortcut None

Enter-BCContainer bc24-rtm # fails becaus of unknown container
Enter-BCContainer BC24-RTM # fails because of WINRM

Full output of scripts


...
Cleanup old dotnet core assemblies
Container BC24-RTM successfully created

Use:
Get-BcContainerEventLog -containerName BC24-RTM to retrieve a snapshot of the event log from the container
Get-BcContainerDebugInfo -containerName BC24-RTM to get debug information about the container
Enter-BcContainer -containerName BC24-RTM to open a PowerShell prompt inside the container
Remove-BcContainer -containerName BC24-RTM to remove the container again
docker logs BC24-RTM to retrieve information about URL's again

 <user> on  ~
# Enter-BcContainer bc24-rtm
Error: No such object: bc24-rtm
Get-BcContainerPlatformVersion Telemetry Correlation Id: 35894752-d9ab-4c45-a230-934cff2e6bea
ParentContainsErrorRecordException: C:\Users\<user>\Documents\PowerShell\Modules\BcContainerHelper\6.0.16\ContainerInfo\Get-NavContainerPlatformVersion.ps1:24
Line |
  24 |      if ($inspect.Config.Labels.psobject.Properties.Match('maintainer' …
     |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | The property 'Config' cannot be found on this object. Verify that the property exists.

 <user> on  ~
# Enter-BcContainer BC24-RTM
New-PSSession: C:\Users\<user>\Documents\PowerShell\Modules\BcContainerHelper\6.0.16\ContainerHandling\Get-NavContainerSession.ps1:67
Line |
  67 |  …  $session = New-PSSession -Credential $credential -ComputerName $cont …
     |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | [BC24-RTM] Connecting to remote server BC24-RTM failed with the following error message : The SSL connection cannot be established. Verify that the service on the remote host is properly configured to listen for HTTPS requests.
     | Consult the logs and documentation for the WS-Management service running on the destination, most commonly IIS or WinRM. If the destination is the WinRM service, run the following command on the destination to analyze and
     | configure the WinRM service: "winrm quickconfig -transport:https". For more information, see the about_Remote_Troubleshooting Help topic.
 thomas on  ~```
freddydk commented 2 months ago

You are running 6.0.16 - I think this is fixed in 6.0.17

The difference is: Open-BcContainer will issue a docker exec -it containername pwsh|powershell in a new prompt in the container Enter-BcContainer will try to create a powershell session to the container and use Enter-PsSession

docker exec takes ~1 second Creating a session takes approx. the same Invoking a command in an established session is very quick.

Invoke-ScriptInBcContainer uses a session if possible, else it will create a .ps1 file with the script and call docker exec to execute the script in the container.

From PowerShell 5 on the host running in admin mode we can create a session using New-PSSession -ContainerId $containerId and use that session

From PowerShell 5 in non-admin mode or from PowerShell 7 (both admin and non-admin) we need to use WinRm. If WinRm is not configured, it will give an error - but enter-bccontainer should revert to open-bccontainer like: image

The error you are getting is that that the SSL Connection cannot be established. On my machine, I also cannot run WinRm over SSL, but it doesn't give an error - instead it reverts to Open-BcContainer as the image above.