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 245 forks source link

Error creating BC25 container with database on host machine #3695

Closed petegonnella closed 3 days ago

petegonnella commented 1 week ago

Describe the issue Error creating BC25 container with database on host machine

Scripts used to create container and cause the issue

$setupDatabaseScript = @'
. 'C:\Run\SetupDatabase.ps1'
if (!$restartingInstance) {
    Copy-NavDatabase -databaseserver $DatabaseServer -databaseInstance $databaseInstance -databaseCredentials $databaseCredentials -sourcedatabaseName $databaseName -destinationDatabaseName "TestAppBC25-$tenantId"
    Copy-NavDatabase -databaseserver $DatabaseServer -databaseInstance $databaseInstance -databaseCredentials $databaseCredentials -sourcedatabaseName $databaseName -destinationDatabaseName "TestAppBC25-tenant"
}
'@

$setupTenantScript = @'
. 'c:\Run\SetupTenant.ps1'
if (!$restartingInstance) {
    Mount-NavDatabase -databaseserver $DatabaseServer -databaseInstance $databaseInstance -databaseCredentials $databaseCredentials -ServerInstance $ServerInstance -TenantId $TenantId -DatabaseName "TestAppBC25-$tenantId"
}
'@
$containerName = "TestAppBC25"

$credential = New-Object pscredential 'admin', (ConvertTo-SecureString -String 'P@ssword101' -AsPlainText -Force)
$dbcredentials = New-Object PSCredential -ArgumentList 'REDACTED', (ConvertTo-SecureString -String 'REDACTED' -AsPlainText -Force)
$artifactUrl = Get-BCArtifactUrl -version 25 -country w1

$databaseName = 'TestAppBC25'

New-BCContainer `
    -accept_eula `
    -containerName $containerName `
    -artifactUrl $artifactUrl `
    -updateHosts `
    -auth UserPassword `
    -Credential $credential `
    -licensefile "e:\container\BC24.bclicense"  `
    -databaseServer 'host.containerhelper.internal' `
    -databaseInstance 'SQL2019' `
    -databaseName $databaseName `
     -PublicDnsName "REDACTED" `
    -memorylimit 32G `
    -databaseCredential $dbcredentials `
    -includeTestToolkit `
    -includePerformanceToolkit `
    -multitenant `
    -myScripts @(
        "https://raw.githubusercontent.com/microsoft/nav-docker/master/generic/Run/HelperFunctions.ps1"
        @{ "SetupDatabase.ps1" = $setupDatabaseScript }
        @{ "SetupTenant.ps1" = $setupTenantScript }
    )

Full output of scripts

BcContainerHelper is version 6.0.24
BcContainerHelper is running as administrator
HyperV is Disabled
Host is Microsoft Windows Server 2019 Standard - 10.0.17763.6293
UsePsSession is True
UsePwshForBc24 is True
UseWinRmSession is allow
UseSslForWinRmSession is True
Docker Client Version is 19.03.5
Docker Server Version is 19.03.5
Removing Session TestAppBC25
Removing container TestAppBC25
Removing entries from hosts
Removing TestAppBC25 from container hosts file
Removing TestAppBC25-* from container hosts file
Removing Desktop shortcuts
Removing C:\ProgramData\BcContainerHelper\Extensions\TestAppBC25
Fetching all docker images
Fetching all docker volumes
WARNING: useTraefik not specified, but Traefik container was initialized, using Traefik. Specify -useTraefik:$false if you do NOT want to use Traefik.
Enabling SSL as otherwise all clients will see mixed HTTP / HTTPS request, which will cause problems e.g. on the mobile and modern windows clients
Using image mcr.microsoft.com/businesscentral:ltsc2019
PublicDnsName is #REDACTED#
Creating Container TestAppBC25
Style: sandbox
Multitenant: Yes
Version: 25.0.23364.24925
Platform: 25.0.24850.0
Generic Tag: 1.0.2.20
Container OS Version: 10.0.17763.5696 (ltsc2019)
Host OS Version: 10.0.17763.6293 (ltsc2019)
WARNING: Host OS and Base Image Container OS doesn't match and HyperV is not installed. If you encounter issues, you could try to install HyperV.
Using process isolation
Using locale en-US
Adding special CheckHealth.ps1 to enable Traefik support
Disabling the standard eventlog dump to container log every 2 seconds (use -dumpEventLog to enable)
Downloading C:\ProgramData\BcContainerHelper\Extensions\TestAppBC25\my\HelperFunctions.ps1
Using license file e:\container\BC24.bclicense
Additional Parameters:
--expose 5986
-e webserverinstance=TestAppBC25
-e publicdnsname=#REDACTED#
-l "traefik.protocol=https"
-l "traefik.web.frontend.rule=PathPrefix:/TestAppBC25"
-l "traefik.web.port=443"
-l "traefik.soap.frontend.rule=PathPrefix:/TestAppBC25soap;ReplacePathRegex: ^/TestAppBC25soap(.*) /BC$1"
-l "traefik.soap.port=7047"
-l "traefik.rest.frontend.rule=PathPrefix:/TestAppBC25rest;ReplacePathRegex: ^/TestAppBC25rest(.*) /BC$1"
-l "traefik.rest.port=7048"
-l "traefik.dev.frontend.rule=PathPrefix:/TestAppBC25dev;ReplacePathRegex: ^/TestAppBC25dev(.*) /BC$1"
-l "traefik.dev.port=7049"
-l "traefik.snap.frontend.rule=PathPrefix:/TestAppBC25snap;ReplacePathRegex: ^/TestAppBC25snap(.*) /BC$1"
-l "traefik.snap.port=7083"
-l "traefik.dl.frontend.rule=PathPrefixStrip:/TestAppBC25dl"
-l "traefik.dl.port=8080"
-l "traefik.dl.protocol=http"
-l "traefik.enable=true"
-l "traefik.frontend.entryPoints=https"
--env customNavSettings=PublicODataBaseUrl=https://#REDACTED#/TestAppBC25rest/odata,PublicSOAPBaseUrl=https://#REDACTED#/TestAppBC25soap/ws,PublicWebBaseUrl=https://#REDACTED#/TestAppBC25
Files in C:\ProgramData\BcContainerHelper\Extensions\TestAppBC25\my:
- AdditionalOutput.ps1
- AdditionalSetup.ps1
- CheckHealth.ps1
- HelperFunctions.ps1
- license.bclicense
- MainLoop.ps1
- SetupDatabase.ps1
- SetupTenant.ps1
- SetupVariables.ps1
- updatehosts.ps1
Creating container TestAppBC25 from image mcr.microsoft.com/businesscentral:ltsc2019
bacfea6f53afa1ad508b7973705bd6c16f9a46cca80c840f95cf242615b6d735
Waiting for container TestAppBC25 to be ready
Using artifactUrl https://bcartifacts-exdbf9fwegejdqak.b02.azurefd.net/sandbox/25.0.23364.24925/w1
Using installer from C:\Run\240
Installing Business Central: multitenant=True, installOnly=False, filesOnly=False, includeTestToolkit=False, includeTestLibrariesOnly=False, includeTestFrameworkOnly=False, includePerformanceToolkit=False, appArtifactPath=c:\dl\sandbox\25.0.23364.24925\w1, platformArtifactPath=c:\dl\sandbox\25.0.23364.24925\platform, databasePath=, licenseFilePath=c:\dl\sandbox\25.0.2
3364.24925\w1\Cronus.bclicense, rebootContainer=True
Installing from artifacts
Starting Local SQL Server
Starting Internet Information Server
Copying Service Tier Files
c:\dl\sandbox\25.0.23364.24925\platform\ServiceTier\Program Files
c:\dl\sandbox\25.0.23364.24925\platform\ServiceTier\System64Folder
Copying Web Client Files
c:\dl\sandbox\25.0.23364.24925\platform\WebClient\Microsoft Dynamics NAV
Copying ModernDev Files
c:\dl\sandbox\25.0.23364.24925\platform
c:\dl\sandbox\25.0.23364.24925\platform\ModernDev\program files\Microsoft Dynamics NAV
Copying additional files
Copying ConfigurationPackages
C:\dl\sandbox\25.0.23364.24925\platform\ConfigurationPackages
Copying Test Assemblies
C:\dl\sandbox\25.0.23364.24925\platform\Test Assemblies
Copying Extensions
C:\dl\sandbox\25.0.23364.24925\w1\Extensions
Copying Applications
C:\dl\sandbox\25.0.23364.24925\platform\Applications
Copying dependencies
Importing PowerShell Modules
Skipping restore of Cronus database
Modifying Business Central Service Tier Config File for Docker
Creating Business Central Service Tier
Installing SIP crypto provider: 'C:\Windows\System32\NavSip.dll'
Installation took 23 seconds
Installation complete
Initializing...
Setting host.containerhelper.internal to 172.28.32.1 in container hosts file
Starting Container
Hostname is TestAppBC25
PublicDnsName is #REDACTED#
Using NavUserPassword Authentication
Import Encryption Key
Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. Could not find or load a specific file. (0x80131621)
at <ScriptBlock>, <No file>: line 15
at <ScriptBlock>, <No file>: line 1Error
Using artifactUrl https://bcartifacts-exdbf9fwegejdqak.b02.azurefd.net/sandbox/25.0.23364.24925/w1
Using installer from C:\Run\240
Installing Business Central: multitenant=True, installOnly=False, filesOnly=False, includeTestToolkit=False, includeTestLibrariesOnly=False, includeTestFrameworkOnly=False, includePerformanceToolkit=False, appArtifactPath=c:\dl\sandbox\25.0.23364.24925\w1, platformArtifactPath=c:\dl\sandbox\25.0.23364.24925\platform, databasePath=, licenseFilePath=c:\dl\sandbox\25.0.2
3364.24925\w1\Cronus.bclicense, rebootContainer=True
Installing from artifacts
Starting Local SQL Server
Starting Internet Information Server
Copying Service Tier Files
c:\dl\sandbox\25.0.23364.24925\platform\ServiceTier\Program Files
c:\dl\sandbox\25.0.23364.24925\platform\ServiceTier\System64Folder
Copying Web Client Files
c:\dl\sandbox\25.0.23364.24925\platform\WebClient\Microsoft Dynamics NAV
Copying ModernDev Files
c:\dl\sandbox\25.0.23364.24925\platform
c:\dl\sandbox\25.0.23364.24925\platform\ModernDev\program files\Microsoft Dynamics NAV
Copying additional files
Copying ConfigurationPackages
C:\dl\sandbox\25.0.23364.24925\platform\ConfigurationPackages
Copying Test Assemblies
C:\dl\sandbox\25.0.23364.24925\platform\Test Assemblies
Copying Extensions
C:\dl\sandbox\25.0.23364.24925\w1\Extensions
Copying Applications
C:\dl\sandbox\25.0.23364.24925\platform\Applications
Copying dependencies
Importing PowerShell Modules
Skipping restore of Cronus database
Modifying Business Central Service Tier Config File for Docker
Creating Business Central Service Tier
Installing SIP crypto provider: 'C:\Windows\System32\NavSip.dll'
Installation took 23 seconds
Installation complete
Initializing...
Setting host.containerhelper.internal to 172.28.32.1 in container hosts file
Starting Container
Hostname is TestAppBC25
PublicDnsName is #REDACTED#
Using NavUserPassword Authentication
Import Encryption Key
Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. Could not find or load a specific file. (0x80131621)

Additional context This happens all the time when creating BC25 container with external SQL database

freddydk commented 1 week ago

I think the problem here is PS5/PS7 I assume that your script also doesn't work with BC 24?

petegonnella commented 6 days ago

@freddydk BC24 is working fine, just tried with the https://bcartifacts-exdbf9fwegejdqak.b02.azurefd.net/sandbox/25.0.23364.25044/w1 artifacts.

petegonnella commented 6 days ago

@freddydk BC24 is working fine, just tried with the https://bcartifacts-exdbf9fwegejdqak.b02.azurefd.net/sandbox/25.0.23364.25044/w1 artifacts.

I also tried executing using Powershell 7.4.5 on host machine, still doesn't work for BC25

freddydk commented 6 days ago

I tried this script on my machine:

$containerName = "bcserver"
$credential = New-Object pscredential 'admin', (ConvertTo-SecureString -String 'mypassword' -AsPlainText -Force)
$artifactUrl = Get-BCArtifactUrl -country us -select latest
$artifactLocation = Download-Artifacts -artifactUrl $artifactUrl -includePlatform
$licenseFile = (Get-ChildItem -Path $artifactLocation[0] -Recurse -Filter '*.bclicense')[0].FullName
$databaseSecurePassword = ConvertTo-SecureString -String 'mypassword' -AsPlainText -Force

$databaseParams = @{
    "databaseServer" = 'host.containerhelper.internal'
    "databaseInstance" = ''
    "databasePrefix" = $containerName
    "databaseName" = '.containers.local'
    "databaseCredential" = New-Object pscredential 'sa', $databaseSecurePassword
    "multitenant" = $true
}

New-BcContainer @databaseParams -replaceExternalDatabases `
    -accept_eula `
    -artifactUrl $artifactUrl `
    -containerName $containerName `
    -auth UserPassword `
    -Credential $credential `
    -licenseFile $licenseFile `
    -enableTaskScheduler -alwaysPull

Which works fine - so there is nothing wrong with BC25, docker and SQL on the host.

You are however restoring the databases in a different way, which might cause this. The problem might be that the SetupDatabase and SetupTenant scripts are running in PS5 inside the container - maybe you should do the database restore before creating the container and then just create a container pointing to the database.

freddydk commented 5 days ago

I can see you are using an old generic image for BC - please try to all -alwayspull

The next BcContainerHelper preview will include a mechanism to add -alwaysPull if the generic image isn't at least as new as BcContainerHelper.

petegonnella commented 5 days ago

I can see you are using an old generic image for BC - please try to all -alwayspull

The next BcContainerHelper preview will include a mechanism to add -alwaysPull if the generic image isn't at least as new as BcContainerHelper.

thanks @freddydk this was the solution 👍