Skip to content

Instantly share code, notes, and snippets.

@hbulens
Created June 27, 2024 12:10
Show Gist options
  • Save hbulens/68fa3d3b3f1f39a416297c08de171988 to your computer and use it in GitHub Desktop.
Save hbulens/68fa3d3b3f1f39a416297c08de171988 to your computer and use it in GitHub Desktop.
Create a Docker container that runs MS Dynamics 365 Business Central
<#
.SYNOPSIS
Gets and deploys Business Central in a Docker container.
.DESCRIPTION
Downloads the image from the registry and deploys it to a Docker container.
This is done using the NavContainerHelper PowerShell module.
.PARAMETER bcVersion
See this blog for more information: https://freddysblog.com/2020/06/25/working-with-artifacts/
.PARAMETER containerName
Name of the new container (if the container already exists it will be replaced)
.PARAMETER useShortcuts
Use this switch to create desktop shortcuts
.PARAMETER includeTestToolkit
Use this switch too include the test toolkit
.PARAMETER memoryLimit
Memory limit for the container (default is unlimited for Windows Server host else 4G)
.PARAMETER dns
Use this parameter to override the default dns settings in the container (corresponds to --dns on docker run)
.PARAMETER sharedDrive
The path of the shared drive where to drop the license file
.PARAMETER licensefile
The path of the license file
.PARAMETER user
The admin user name
.PARAMETER password
The admin password
#>
param(
[Parameter(mandatory = $false, HelpMessage = "The BC version")]
[String]$bcVersion = '23.0',
[Parameter(mandatory = $false, HelpMessage = "The name of the container")]
[String]$containerName = 'BC23',
[Parameter(mandatory = $false, HelpMessage = "Switch to include shortcuts")]
[Switch]$useShortcuts = $true,
[Parameter(mandatory = $false, HelpMessage = "Switch to include test toolkit")]
[Switch]$includeTestToolkit = $false,
[Parameter(mandatory = $false, HelpMessage = "Memory limit for the container (default is unlimited for Windows Server host else 4G-8G should be enough)")]
[string]$memoryLimit = "8G",
[Parameter(mandatory = $false, HelpMessage = "Use this parameter to override the default dns settings in the container (corresponds to --dns on docker run)")]
[string]$dns = '8.8.8.8',
[Parameter(mandatory = $false, HelpMessage = "The local drive to share with the Docker container")]
[String]$sharedDrive = 'C:\docker\DS',
[Parameter(mandatory = $false, HelpMessage = "The BC license file")]
[String]$licensefile = 'c:\temp\BC.bclicense',
[Parameter(mandatory = $false, HelpMessage = "The BC admin")]
[String]$user = 'admin',
[Parameter(mandatory = $false, HelpMessage = "The BC admin password")]
[String]$password = 'admin'
)
Write-Output ""
Write-Output ""
Write-Output "*"
Write-Output "**"
Write-Output "***"
Write-Output "****"
Write-Output "*****"
Write-Output "******"
Write-Output "*******"
Write-Output "********"
Write-Output "*********"
Write-Output "**********"
Write-Output "***********"
Write-Output "************"
Write-Output ""
Write-Output "_____ _ _____ _ _ _"
Write-Output "| __ \(_) / ____| | | | | | |"
Write-Output "| | | |_ _ __ ___ ___ | (___ ___| |__ ___ __| |_ _| | ___ _ __"
Write-Output "| | | | | '_ ` _ \ / _ \ \___ \ / __| '_ \ / _ \/ _` | | | | |/ _ \ '__|"
Write-Output "| |__| | | | | | | | __/_ ____) | (__| | | | __/ (_| | |_| | | __/ |"
Write-Output "|_____/|_|_| |_| |_|\___(_)_____/ \___|_| |_|\___|\__,_|\__,_|_|\___|_|"
Write-Output ""
Write-Output ""
Write-Output "Creating Docker container $containerName for version $bcVersion "
Write-Output ""
Write-Output "************"
Write-Output "***********"
Write-Output "**********"
Write-Output "*********"
Write-Output "********"
Write-Output "*******"
Write-Output "******"
Write-Output "*****"
Write-Output "****"
Write-Output "***"
Write-Output "**"
Write-Output "*"
Write-Output ""
Write-Output ""
Install-Module BcContainerHelper -force
$accept_eula = $true
$appbacpacuri = ''
$tenantbacpacuri = ''
# Shared drive
$additionalParameters = @("-v" + $sharedDrive + ":c:\dsfiles")
if ($appbacpacuri -ne '' -and $tenantbacpacuri -ne '') {
$additionalParameters += @("--env appbacpac=""$appbacpacuri""", "--env tenantBacpac=""$tenantbacpacuri""")
}
# Build credentials
$pw = ConvertTo-SecureString -String $password -AsPlainText -Force
$credential = New-Object PSCredential $user, $pw
# Fetch the URL of the requested container
$artifactUrl = Get-BCArtifactUrl -type OnPrem -version $bcVersion -country w1
Write-Output "Artifact URL for $bcVersion : $artifactUrl"
# Value for shortcuts: None, Desktop or StartMenu
$shortCuts = 'None';
if ($useShortcuts.IsPresent) {
$shortCuts = 'Desktop';
}
New-NavContainer -accept_eula:$accept_eula `
-containerName $containerName `
-auth UserPassword `
-Credential $credential `
-alwaysPull `
-doNotExportObjectsToText `
-usessl:$false `
-updateHosts `
-assignPremiumPlan `
-shortcuts $shortcuts `
-artifactUrl $artifactUrl `
-additionalParameters $additionalParameters `
-ACCEPT_OUTDATED `
-licenseFile $licensefile `
-includeTestToolkit:$includeTestToolkit.IsPresent `
-includetestlibrariesonly `
-memoryLimit $memoryLimit `
-dns $dns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment