New-BcContainerWizzard generates scripts to build NAV or Business Central containers
Silviu Virlan
Microsoft MVP | MCT | Author | Dynamics 365 Business Central Supervisor at RSM US LLP | ERP, Dynamics NAV Expert
Last few months I found myself reading increasingly more about Docker and Microsoft Powershell libraries that get you a running instance of NAV or Business Central in a local container.
I am going to investigate 3 ways that get you a running NAV/BC container.
Using pure docker command
You can start with Docker here.
Example of using docker to create first BC container:
docker run -e accept_eula=y mcr.microsoft.com/businesscentral/sandbox
This command will set an environment variable local to the new container and will pull (if not already pulled) the image specified (mcr.microsoft.com/businesscentral/sandbox) and will run it.
You could also run the container based on a Business Central image for Windows Server 2019. This is a lighter image than the previous one, which was for Windows 10 OS.
docker run -e accept_eula=y mcr.microsoft.com/businesscentral/sandbox:ltsc2019
To check the size of the images downloaded run from the command prompt:
docker image list
If you want to delete some of your images run for each the following:
docker image rm 0d -f
You can specify the whole identifier for the image or just the first 2 letters (0d).
With the container running, you can open VS Code, install AL code using the ALLanguage.vsix from the location displayed in the log:
https://e8d9bbb19805:8080/ALLanguage.vsix
If you have trouble using the DNS name, something must not have been right with the writing to the hosts file, but you could always use the IP of the container.
Now you should be able to connect to your container and start writing extensions.
Using Microsoft's module NAVContainerHelper, more specifically "New-NAVContainer" command:
New-NavContainer -accept_eula -containerName "firstcontainer" -auth Windows -imageName mcr.microsoft.com/businesscentral/sandbox:ltsc2019
While previous command could have been launched from the command prompt (with docker running), you can launch the above command from the prompt of Powershell ISE (run as admin). This will pull the latest business central image for Windows Server 2019. If you run "docker image ls" you can notice this is a lighter image.
You can connect to that instance to write extensions by running VS Code and installing vsix file that comes with the container.
Using latest Microsoft's module BcContainerHelper
Latest Microsoft's module, BcContainerHelper, has a command New_BcContainerWizzard. This command generates a Powershell script that, when run, creates a NAV/BC container.
To gain access to the wizzard, install first the new module BcContainerHelper. When running "Install-Module -Name BcContainerHelper" I had an error:
Then I added the "-AllowClobber" parameter and module was successfully installed.
Install-Module -Name BcContainerHelper -AllowClobber
But ideally, you want to live with either NavContainerHelper or BcContainerHelper. If you don't have installed locally NAVContainerHelper, "-AllowClobber" parameter is not needed.
With BcContainerHelper installed I had access to the New-BcContainerWizzard:
Let's launch it and install a container loaded with a NAV 2017 CU5 image:
a) Accept Eula:
Choose Y.
b) Next we need to choose between a locally stored container or a container stored in Azure:
c) For authentication step you have a few options: either username + password or Windows. I choose Windows:
d) Name the new container:
e) Version: latest BC (onprem or Sandbox) or a specific version.
We are going to install a container with an OnPrem image of NAV 2017 CU5. For a list of sandboxes and onprem images consult these links:
https://mcr.microsoft.com/v2/businesscentral/sandbox/tags/list
https://mcr.microsoft.com/v2/businesscentral/onprem/tags/list
f) Specify country
I chose NA.
g) Test toolkit ?
h) License (No, or local file or https url for downloading the license file)
i) Database: you can leave the new container loaded with cronus db in a local (to container) sqlexpress instance or you can load a database with the correct version in the SQLExpress instance or use a SQL Server other than container's SQL Server. I chose the default but planning to connect to the SQL Server express instance and restore a backup later once container is created and runs.
j) DNS settings:
k) Memory Limit:
I left default.
l) CAL Development:
As it is a NAV 2017 image I chose Yes.
Name and save your powershell script:
The window will close and a Powershell ISE opens with the new script:
Now you can distribute the script with your team. If you want to generate the new container press F5.
In the script please note the new parameter artifactURL. More on this new parameter here.
In a few minutes the container was installed. However during the last steps (exporting shortcuts to host desktop) script encountered an error:
In the version of BcContainerHelper I was working with (1.0.1) , Export-BcContainerObjects was not included. In fact, the command should have been Export-NAVContainerObjects.
I created the issue in github and next day I found an email from Freddy that this was a bug and it will be shipped in BcContainerHelper 1.0.2-preview153.
As the new release was made available earlier that morning, I re-installed the module and I was able to finish running the script.
I needed a different database instead of installed Cronus database, so I connected via SSMS to the container SQL instance and restored the database. Now development can take place in the container.