microsoft / navcontainerhelper

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

Problems with docker attach #3337

Closed sorsted closed 7 months ago

sorsted commented 7 months ago

Describe the issue

I installed Business Central in a container using Docker Engine (not Docker Desktop), mostly following this guide: https://www.youtube.com/watch?v=lPKkKbLaQ9Y

The PowerShell script for the installation and its output can be found below.

I would then like to be able to run commands in the container. So I do docker start bcserver, which works fine, and then follow up with docker attach bcserver. Then nothing happens, and no output ever being produced. So I press Ctrl + C to stop the process and then repeat both docker start bcserver and docker attach bcserver. This time, something does happen, namely:

Starting Internet Information Server
Starting Service Tier
Container IP Address: 172.17.92.124
Container Hostname  : bcserver
Container Dns Name  : bcserver
Web Client          : https://bcserver/BC/?tenant=default
Dev. Server         : https://bcserver
Dev. ServerInstance : BC
Dev. Server Tenant  : default
Setting bcserver to 172.17.92.124 in host hosts file
Setting bcserver-default to 172.17.92.124 in host hosts file
Setting bcserver-default to 172.17.92.124 in container hosts file

Files:
http://bcserver:8080/ALLanguage.vsix
http://bcserver:8080/certificate.cer

Container Total Physical Memory is 62.8Gb
Container Free Physical Memory is 39.4Gb

Initialization took 9 seconds
Ready for connections!

And that’s it. No more output is ever produced, and pressing keys yields no reaction.

I also tried docker exec -it bcserver bash, but this just yields:

container e485fea63a7b5b47189e20449de33a313b6c42fdb8415518d45ed94b54966e7e encountered an error during hcs::System::CreateProcess: bash: failure in a Windows system call: The system cannot find the file specified. (0x2)

Scripts used to create container and cause the issue

$containerName = 'bcserver'
$password = 'P@ssw0rd'
$securePassword = ConvertTo-SecureString -String $password -AsPlainText -Force
$credential = New-Object pscredential 'admin', $securePassword
$auth = 'UserPassword'
$artifactUrl = Get-BcArtifactUrl -type 'Sandbox' -country 'dk' -select 'Latest'
New-BcContainer `
    -accept_eula `
    -containerName $containerName `
    -credential $credential `
    -auth $auth `
    -artifactUrl $artifactUrl `
    -usessl -installCertificateOnHost `
    -updateHosts

Full output of scripts

BcContainerHelper version 6.0.5
BC.HelperFunctions emits usage statistics telemetry to Microsoft
BcContainerHelper is version 6.0.5
BcContainerHelper is running as administrator
HyperV is Disabled
UsePsSession is True
Host is Microsoft Windows 10 Enterprise - 10.0.19045.3930
Docker Client Version is 25.0.2
Docker Server Version is 25.0.2
Removing Session bcserver
Removing container bcserver
Removing entries from hosts
Removing bcserver from container hosts file
Removing bcserver-* from container hosts file
Certificate with thumbprint D544B7A87001C51D593B0086EFEB681F7102CC95 removed successfully
Removing Desktop shortcuts
Removing C:\ProgramData\BcContainerHelper\Extensions\bcserver
Downloading artifact /sandbox/23.4.15643.16166/dk
Downloading C:\Users\sers\AppData\Local\Temp\def92ec8-e10b-463a-ba8b-1cf11bc1da02.zip
Downloading using WebClient
Unpacking artifact to tmp folder using Expand-Archive
Downloading platform artifact /sandbox/23.4.15643.16166/platform
Downloading C:\Users\sers\AppData\Local\Temp\4227012b-24aa-4803-afc3-548c6b70d842.zip
Downloading using WebClient
Unpacking artifact to tmp folder using Expand-Archive
Fetching all docker images
Fetching all docker volumes
INFO: Windows 10 21H1/21H2 images are not yet available, using 2004 as these are found to work better than 20H2 on 21H1/21H2
Using image mcr.microsoft.com/businesscentral:10.0.19041.1415
Creating Container bcserver
Style: sandbox
Multitenant: Yes
Version: 23.4.15643.16166
Platform: 23.0.16157.0
Generic Tag: 1.0.2.14
Container OS Version: 10.0.19041.1415 (2004)
Host OS Version: 10.0.19045.3930 (22H2)
WARNING: Host OS is Windows 10 21H1 or newer and Container OS is 2004, defaulting to process isolation. If you experience problems, add -isolation hyperv.
Using process isolation
Using locale da-DK
Disabling the standard eventlog dump to container log every 2 seconds (use -dumpEventLog to enable)
Files in C:\ProgramData\BcContainerHelper\Extensions\bcserver\my:
- AdditionalOutput.ps1
- MainLoop.ps1
- SetupVariables.ps1
- updatehosts.ps1
Creating container bcserver from image mcr.microsoft.com/businesscentral:10.0.19041.1415
e485fea63a7b5b47189e20449de33a313b6c42fdb8415518d45ed94b54966e7e
Waiting for container bcserver to be ready
Using artifactUrl https://bcartifacts.azureedge.net/sandbox/23.4.15643.16166/dk
Using installer from C:\Run\210-new
Installing Business Central
Installing from artifacts
Starting Local SQL Server
Starting Internet Information Server
Copying Service Tier Files
c:\dl\sandbox\23.4.15643.16166\platform\ServiceTier\Program Files
c:\dl\sandbox\23.4.15643.16166\platform\ServiceTier\System64Folder
Copying PowerShell Scripts
c:\dl\sandbox\23.4.15643.16166\platform\WindowsPowerShellScripts\Cloud\NAVAdministration
c:\dl\sandbox\23.4.15643.16166\platform\WindowsPowerShellScripts\WebSearch
Copying Web Client Files
c:\dl\sandbox\23.4.15643.16166\platform\WebClient\Microsoft Dynamics NAV
Copying ModernDev Files
c:\dl\sandbox\23.4.15643.16166\platform
c:\dl\sandbox\23.4.15643.16166\platform\ModernDev\program files\Microsoft Dynamics NAV
Copying additional files
Copying ConfigurationPackages
C:\dl\sandbox\23.4.15643.16166\dk\ConfigurationPackages
Copying Test Assemblies
C:\dl\sandbox\23.4.15643.16166\platform\Test Assemblies
Copying Extensions
C:\dl\sandbox\23.4.15643.16166\dk\Extensions
Copying Applications
C:\dl\sandbox\23.4.15643.16166\platform\Applications
Copying Applications.DK
C:\dl\sandbox\23.4.15643.16166\dk\Applications.DK
Copying dependencies
Copying ReportBuilder
Importing PowerShell Modules
Restoring CRONUS Demo Database
Setting CompatibilityLevel for tenant on localhost\SQLEXPRESS
Exporting Application to CRONUS
Removing Application from tenant
Modifying Business Central Service Tier Config File for Docker
Creating Business Central Service Tier
Installing SIP crypto provider: 'C:\Windows\System32\NavSip.dll'
Starting Business Central Service Tier
Importing license file
Copying Database on localhost\SQLEXPRESS from tenant to default
Taking database tenant offline
Copying database files
Attaching files as new Database default
Putting database tenant back online
Mounting tenant database
Mounting Database for default on server localhost\SQLEXPRESS with AllowAppDatabaseWrite = False
Sync'ing Tenant
Tenant is Operational
Stopping Business Central Service Tier
Installation took 109 seconds
Installation complete
Initializing...
Setting host.docker.internal to 100.81.21.89 in container hosts file (copy from host hosts file)
Setting gateway.docker.internal to 100.81.21.89 in container hosts file (copy from host hosts file)
Setting kubernetes.docker.internal to 127.0.0.1 in container hosts file (copy from host hosts file)
Setting host.containerhelper.internal to 172.17.80.1 in container hosts file
Starting Container
Hostname is bcserver
PublicDnsName is bcserver
WARNING: DNS resolution not working from within the container.
Using NavUserPassword Authentication
Creating Self Signed Certificate
Self Signed Certificate Thumbprint 486589C0B69667930C9E361F3C81DD98571B379B
DNS identity bcserver
Modifying Service Tier Config File with Instance Specific Settings
Starting Service Tier
CertificateThumprint 486589C0B69667930C9E361F3C81DD98571B379B
Registering event sources
Creating DotNetCore Web Server Instance
Using application pool name: BC
Using default container name: NavWebApplicationContainer
Copy files to WWW root C:\inetpub\wwwroot\BC
Create the application pool BC
Create website: NavWebApplicationContainer with SSL
Update configuration: navsettings.json
Done Configuring Web Client
Enabling Financials User Experience
Dismounting Tenant
Mounting Tenant
Mounting Database for default on server localhost\SQLEXPRESS with AllowAppDatabaseWrite = False
Sync'ing Tenant
Tenant is Operational
Creating http download site
Setting SA Password and enabling SA
Creating admin as SQL User and add to sysadmin
Creating SUPER user
Container IP Address: 172.17.80.145
Container Hostname  : bcserver
Container Dns Name  : bcserver
Web Client          : https://bcserver/BC/?tenant=default
Dev. Server         : https://bcserver
Dev. ServerInstance : BC
Dev. Server Tenant  : default
Setting bcserver to 172.17.80.145 in host hosts file
Setting bcserver-default to 172.17.80.145 in host hosts file
Setting bcserver-default to 172.17.80.145 in container hosts file

Files:
http://bcserver:8080/ALLanguage.vsix
http://bcserver:8080/certificate.cer

WARNING: You are running a container which is 704 days old.
Microsoft recommends that you always run the latest version of our containers.

Container Total Physical Memory is 62.8Gb
Container Free Physical Memory is 38.4Gb

Initialization took 20 seconds
Ready for connections!
Reading CustomSettings.config from bcserver
Importing certificate in host's certificate store
Creating Desktop Shortcuts for bcserver
Cleanup old dotnet core assemblies
Container bcserver successfully created

Use:
Get-BcContainerEventLog -containerName bcserver to retrieve a snapshot of the event log from the container
Get-BcContainerDebugInfo -containerName bcserver to get debug information about the container
Enter-BcContainer -containerName bcserver to open a PowerShell prompt inside the container
Remove-BcContainer -containerName bcserver to remove the container again
docker logs bcserver to retrieve information about URL's again
...
freddydk commented 7 months ago

Docker attach attaches the the main loop, which is a message pump - nothing really to do there. The reason for your docker exec -it bcserver bash not working is that bash doesn't exist. Use PowerShell instead - docker exec -it bcserver powershell Current generic images use powershell 5 - pwsh is also not installed.

You can also use the BcContainerHelper command Invoke-ScriptInBcContainer, which pre-loads all BC CmdLets, Example:

Invoke-ScriptInBcContainer -containername bcserver -scriptblock {
    get-navserverinstance
}