How-To update outdated BC License in Docker Containers

Perhaps you have already come across this topic. If you run into an expired Business Central or Dynamics NAV license in your containers, the update of the license does not work via Import-NavContainerLicense(). As some colleagues have described it in this issue on GitHub, the instance might no longer be accessible due to the expired license. However, in this very post there was an additional tip to work around this problem. Namely, by resetting the date of the host to a valid date from the point of view of the expired license. Now, after a container restart, you’re able to install the new license.

Since I don’t want to change the date for the whole host or restart the container, I built a small function that changes the date only temporarily inside the container, imports the license and then corrects it again.

The error message

ServerInstance 'MicrosoftDynamicsNavServer$BC' is not running.
at <ScriptBlock>, <No file>: line 4
ServerInstance 'MicrosoftDynamicsNavServer$BC' is not running.
At C:\Program Files\WindowsPowerShell\Modules\navcontainerhelper\0.7.0.4\ContainerHandling\Invoke-ScriptInNavContainer.ps1:37 char:13
+             Invoke-Command -Session $session -ScriptBlock $scriptbloc ...

Update outdated BC License in Docker

Update-OutdatedNavLicense -ContainerName "MY-CONTAINER" -NavLicense "C:\Temp\MyNewNavLicense.flf"

The function required for this looks like this:

######################################
# Update outdated BC License in Docker
######################################

function Update-OutdatedNavLicense {
    param (
        [string]$ContainerName = '',
        [string]$NavInstance = 'BC',
        [string]$NavLicense = ''
    )
   
    # Copy the license to the shared volume
    Copy-Item $NavLicense -Destination "C:\ProgramData\BcContainerHelper\Extensions\$ContainerName\my\dev.flf" -Force -ErrorAction SilentlyContinue
    
    Invoke-ScriptInBcContainer -containerName $ContainerName -scriptblock {
        Param($NavInstance)

        #Reset container date to last year
        $arguments = "& Set-Date -Date (Get-Date).AddDays(-365)"
        Start-Process powershell -Verb runAs -ArgumentList $arguments
    
        #Import the license from the shared path
        Import-NAVServerLicense $NavInstance -LicenseData ([Byte[]]$(Get-Content -Path "c:\run\my\dev.flf" -Encoding Byte))
    
        #Reset container date to current date
        $arguments = "& Set-Date -Date (Get-Date).AddDays(365)"
        Start-Process powershell -Verb runAs -ArgumentList $arguments
    
    }  -ArgumentList $NavInstance 
}
Update outdated BC License in Docker

I hope this function helps one or the other to update outdated BC License in Docker containers.

... is a technical consultant and developer at Comsol Unternehmenslösungen AG in Kronberg/Taunus. Major tasks are the architecture and implementation of complex, usually cross-system applications in and around Microsoft Dynamics 365 Business Central.

Leave a Reply

Your email address will not be published. Required fields are marked *