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

Docker error in New-BcContainer for BC23 #3234

Closed floyd-chan closed 10 months ago

floyd-chan commented 10 months ago

This script worked yesterday for creating a BC22 sandbox container.

Today, I changed the version variable to create a BC23 sandbox container, but when I run the script it fails with a Docker error and the container is partially created but useable.

What is the likely cause?

Here is the script:

#-[ VARIABLES ]-----------------------
$bcVersion = '23.0.12034.13705'

$containerName = 'saas'

$bcAuth = "UserPassword"
$bcUserName = 'floyd'
$bcUserPassword = ConvertTo-SecureString 'floyd' -AsPlainText -Force 

$dbServer = '172.16.90.60' # use Server IP instead of Server Name to avoid error: "Cannot establish a connection to the SQL Server/Database."
$dbInstance = ''
$dbSaName = 'sa' 
$dbSaPassword = ConvertTo-SecureString 'XXX' -AsPlainText -Force

#-[ PREREQUISITES ]-----------------------
Import-Module -Name Az
Import-Module -Name bccontainerhelper

#-[ Get BC Artifact URL ]-----------------------
$artifactUrl = Get-BCArtifactUrl `
    -country 'US' `
    -version $bcVersion `
    -select Closest

$artifactUrl

#-[ Get BC License ]-----------------------
$licenseFile = 'T:\!_BACPAC\5356620.bclicense'

#-[ Create Multi-Tenant BC Container ]-----------------------
$userCredential = New-Object pscredential `
    -ArgumentList $bcUserName, $bcUserPassword
$dbCredential = New-Object pscredential `
    -ArgumentList $dbSaName, $dbSaPassword

$databaseParams = @{
    "databaseServer" = $dbServer
    "databaseInstance" = $dbInstance
    "databasePrefix" = "$($containerName)-"
    "databaseName" = "CRONUS"
    "databaseCredential" = $dbCredential
    "multitenant" = $true
}

Write-Host ('')
Write-Host ("Creating new container " + $containerName + "...") -ForegroundColor Yellow 
New-BcContainer @databaseParams -replaceExternalDatabases `
    -accept_eula `
    -accept_outdated `
    -alwaysPull `
    -auth $bcAuth `
    -artifactUrl $artifactUrl `
    -containerName $containerName `
    -credential $userCredential `
    -enableTaskScheduler `
    -isolation hyperv `
    -licenseFile $licenseFile `
    -updateHosts `
    -useSSL $false

Write-Host ("New container created.") -ForegroundColor Yellow 

Here is the output:

PowerShell Extension v2023.8.0
Copyright (c) Microsoft Corporation.

https://aka.ms/vscode-powershell
Type 'help' to get help.

PS W:\_REPOS\Qixas-Tools\Qixas Scripts>
PS W:\_REPOS\Qixas-Tools\Qixas Scripts> . {
#-[ VARIABLES ]-----------------------
$bcVersion = '23.0.12034.13705'

$containerName = 'saas'

$bcAuth = "UserPassword"
$bcUserName = 'floyd'
$bcUserPassword = ConvertTo-SecureString 'floyd' -AsPlainText -Force 

$dbServer = '172.16.90.60' # use Server IP instead of Server Name to avoid error: "Cannot establish a connection to the SQL Server/Database."
$dbInstance = ''
$dbSaName = 'sa' 
$dbSaPassword = ConvertTo-SecureString 'kr!tt3rs' -AsPlainText -Force

#-[ PREREQUISITES ]-----------------------
Import-Module -Name Az
Import-Module -Name bccontainerhelper

#-[ Get BC Artifact URL ]-----------------------
$artifactUrl = Get-BCArtifactUrl `
    -country 'US' `
    -version $bcVersion `
    -select Closest

$artifactUrl

#-[ Get BC License ]-----------------------
$licenseFile = 'T:\!_BACPAC\5356620.bclicense'

#-[ Create Multi-Tenant BC Container ]-----------------------
$userCredential = New-Object pscredential `
    -ArgumentList $bcUserName, $bcUserPassword
$dbCredential = New-Object pscredential `
    -ArgumentList $dbSaName, $dbSaPassword

$databaseParams = @{
    "databaseServer" = $dbServer
    "databaseInstance" = $dbInstance
    "databasePrefix" = "$($containerName)-"
    "databaseName" = "CRONUS"
    "databaseCredential" = $dbCredential
    "multitenant" = $true
}

Write-Host ('')
Write-Host ("Creating new container " + $containerName + "...") -ForegroundColor Yellow
New-BcContainer @databaseParams -replaceExternalDatabases `
    -accept_eula `
    -accept_outdated `
    -alwaysPull `
    -auth $bcAuth `
    -artifactUrl $artifactUrl `
    -containerName $containerName `
    -credential $userCredential `
    -enableTaskScheduler `
    -isolation hyperv `
    -licenseFile $licenseFile `
    -updateHosts `
    -useSSL $false

Write-Host ("New container created.") -ForegroundColor Yellow

}
WARNING: The names of some imported commands from the module 'Microsoft.Azure.PowerShell.Cmdlets.Network' include unapproved verbs that might make them 
less discoverable. To find the commands with unapproved verbs, run the Import-Module command again with the Verbose parameter. For a list of approved     
verbs, type Get-Verb.
WARNING: The names of some imported commands from the module 'Az.Network' include unapproved verbs that might make them less discoverable. To find the 
commands with unapproved verbs, run the Import-Module command again with the Verbose parameter. For a list of approved verbs, type Get-Verb.
BcContainerHelper version 6.0.0
BC.HelperFunctions emits usage statistics telemetry to Microsoft
WARNING: The names of some imported commands from the module 'bccontainerhelper' include unapproved verbs that might make them less discoverable. To find
 the commands with unapproved verbs, run the Import-Module command again with the Verbose parameter. For a list of approved verbs, type Get-Verb.
https://bcartifacts.azureedge.net/sandbox/23.0.12034.13705/us

Creating new container saas...
BcContainerHelper is version 6.0.0
BcContainerHelper is running as administrator
HyperV is Enabled
UsePsSession is True
Host is Microsoft Windows 11 Enterprise - 10.0.22621.2715
Docker Client Version is 18.09.8
Docker Server Version is 18.09.8
Removing Desktop shortcuts
Setting database saas-tenant offline
Removing database saas-tenant
Setting database saas-CRONUS offline
Removing database saas-CRONUS
Starting Database Restore job from https://bcartifacts.azureedge.net/sandbox/23.0.12034.13705/us
C:\Program Files\WindowsPowerShell\Modules\bccontainerhelper\6.0.0\Import-BcContainerHelper.ps1
Fetching all docker images
Fetching all docker volumes
ArtifactUrl and ImageName specified
WARNING: Unable to find matching generic image for your host OS. Using mcr.microsoft.com/businesscentral:10.0.20348.2031
Building multitenant image false:sandbox-23.0.12034.13705-us-nodb-mt based on mcr.microsoft.com/businesscentral:10.0.20348.2031 with https://bcartifacts.azureedge.net/sandbox/23.0.12034.13705/us without database
Pulling latest image mcr.microsoft.com/businesscentral:10.0.20348.2031
10.0.20348.2031: Pulling from businesscentral
Generic Tag: 1.0.2.14
Container OS Version: 10.0.20348.2031 (ltsc2022)
Host OS Version: 10.0.22621.2715 (22H2)
Using hyperv isolation
Using license file T:\!_BACPAC\5356620.bclicense
Files in c:\bcartifacts.cache\mnhgbgbs.3gc\my:
Copying Platform Artifacts
c:\bcartifacts.cache\sandbox\23.0.12034.13705\platform
Copying ConfigurationPackages
C:\bcartifacts.cache\sandbox\23.0.12034.13705\us\ConfigurationPackages
Copying Extensions
C:\bcartifacts.cache\sandbox\23.0.12034.13705\us\Extensions
Copying Applications.US
C:\bcartifacts.cache\sandbox\23.0.12034.13705\us\Applications.US
c:\bcartifacts.cache\mnhgbgbs.3gc
Sending build context to Docker daemon  1.903GB

Step 1/6 : FROM mcr.microsoft.com/businesscentral:10.0.20348.2031
 ---> a28a216749db
Step 2/6 : ENV DatabaseServer=localhost DatabaseInstance=SQLEXPRESS DatabaseName=CRONUS IsBcSandbox=Y artifactUrl=https://bcartifacts.azureedge.net/sandbox/23.0.12034.13705/us filesOnly=False
 ---> Running in 3fcf65d78012
Removing intermediate container 3fcf65d78012
 ---> 066d9a18d5d2
Step 3/6 : COPY my /run/
 ---> e1d7be96115a
Step 4/6 : COPY NAVDVD /NAVDVD/
 ---> 68a33f39b93c
Step 5/6 : RUN \Run\start.ps1 -installOnly -multitenant
 ---> Running in 03e3ebf6363d
c:\run\my folder doesn't exist, creating it
Using installer from C:\Run\210-new
Installing Business Central
Installing from DVD
Starting Local SQL Server
Starting Internet Information Server
Copying Service Tier Files
C:\NAVDVD\ServiceTier\Program Files
C:\NAVDVD\ServiceTier\System64Folder
Copying PowerShell Scripts
C:\NAVDVD\WindowsPowerShellScripts\Cloud\NAVAdministration
C:\NAVDVD\WindowsPowerShellScripts\WebSearch
Copying Web Client Files
C:\NAVDVD\WebClient\Microsoft Dynamics NAV
Copying ModernDev Files
C:\NAVDVD
Copying additional files
Copying ConfigurationPackages
C:\NAVDVD\ConfigurationPackages
Copying Test Assemblies
C:\NAVDVD\Test Assemblies
Copying Extensions
C:\NAVDVD\Extensions
Copying Applications
C:\NAVDVD\Applications
Copying Applications.US
C:\NAVDVD\Applications.US
Copying dependencies
Copying ReportBuilder
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 26 seconds
Installation complete
New-Bcimage Telemetry Correlation Id: 605c6e73-a665-4dcc-9147-4fdb1f364af5
New-BcContainer Telemetry Correlation Id: 035768c6-63c9-4d9c-9f0b-5191870e8d28
DockerDo : re-exec error: exit status 1: output: time="2023-11-16T15:46:03-05:00" level=error msg="hcsshim::ImportLayer failed in Win32: The system
cannot find the path specified. (0x3)
path=\\\\?\\C:\\ProgramData\\docker\\windowsfilter\\9b02e9f68241373c78c4cdaf8964f6fec3430f10e188d2e95dbd35b9a212161a
folder=C:\\ProgramData\\docker\\tmp\\hcs030992335"
unexpected EOF
ExitCode: 1
Commandline: docker build --isolation=hyperv --memory 8G --no-cache --tag false:sandbox-23.0.12034.13705-us-nodb-mt c:\bcartifacts.cache\mnhgbgbs.3gc
At C:\Program Files\WindowsPowerShell\Modules\bccontainerhelper\6.0.0\ContainerHandling\New-NavImage.ps1:694 char:27
+ ...       if (!(DockerDo -command build -parameters @("--isolation=$isola ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,DockerDo

PS W:\_REPOS\Qixas-Tools\Qixas Scripts>
swomkbb commented 10 months ago

Hey... I have exact the same issue since few days. It fails in the same place as in example above (on docker build command). I know that some collegues from my company also have the same problem in other projects.

New-BcContainer Telemetry Correlation Id: d6bcc158-e217-43fb-909c-9f923a5876ff Removing Desktop shortcuts Run-AlPipeline Telemetry Correlation Id: a167d25b-e6a5-4fb8-964f-40a614856395 DockerDo : re-exec error: exit status 1: output: hcsshim::ImportLayer failed in Win32: The system cannot find the path specified. (0x3) ExitCode: 1 Commandline: docker build --isolation=process --memory 7G --no-cache --tag my:sandbox-23.1.13431.14059-pl-mt c:\bcartifacts.cache\evie5cqv.in3 At C:\Program Files\WindowsPowerShell\Modules\bccontainerhelper\6.0.0\ContainerHandling\New-NavImage.ps1:694 char:27

[error]PowerShell exited with code '1'.

hannib84 commented 10 months ago

Hi I have exact same issue here. It started on Wednesday then I was able to run it during Thursday, but now it crashing again.

Installation complete New-Bcimage Telemetry Correlation Id: 61aa7704-7249-4192-8eb8-f0aec0874335 New-BcContainer Telemetry Correlation Id: 981e0ad8-b998-42af-bbee-f842f6e2c8ff Removing Desktop shortcuts Run-AlPipeline Telemetry Correlation Id: 6397db8b-5eb3-45e0-9f45-92f2fe4b740c

[error]DockerDo : re-exec error: exit status 1: output: hcsshim::ImportLayer failed in Win32: The system cannot find the path

specified. (0x3) ExitCode: 1 Commandline: docker build --isolation=process --memory 8G --no-cache --tag my:onprem-21.2.49946.49990-se c:\bcartifacts.cache\j1gnd3qv.hqp At C:\Program Files\WindowsPowerShell\Modules\bccontainerhelper\6.0.0\ContainerHandling\New-NavImage.ps1:694 char:27

Athystrup commented 10 months ago

We also have the same problem on some of our build servers. It seems to be related to the creation of images. We have one server, which managed to pull the BC image yesterday, and it runs fine now. The other two servers however, fail at the exact same place as above.

freddydk commented 10 months ago

@floyd-chan - the reason your script fails is a missing colon between -useSSL and $false in the last line: image

-useSSL is a switch parameter which means that your $false will by powershell be used as a parameter to the imageName parameter - so your script will create an image (which fails).

Delete the last line and the terminating ` in the line above. (useSSL is false by default anyway)

freddydk commented 10 months ago

The other problems seems to come from image creation - trying to replicate those, but there isn't much data to go with. @Athystrup , @hannib84 and @swomkbb please create a new issue and include script + full output to help me repro this issue.