Codementor Events

Manually Creating a Sandbox Based on Docker

Published Dec 18, 2018

Learn how to manually create a sandbox based on Docker in this article by Stefano Demiliani, a Microsoft Certified Solution Developer (MCSD) and a long-time expert on different Microsoft technologies, and Duilio Tacconi, a Microsoft Dynamics NAV / Microsoft Dynamics 365 Business Central Escalation Engineer at Microsoft EMEA Customer Support & Services (CSS).

You can create a Dynamics 365 Business Central sandbox environment without using the sandbox links to the Business Central production tenant, but instead using custom scripts for creating Docker-based sandboxes hosted locally or on Azure Container Instances.

Steps for manually creating a locally hosted Dynamics 365 Business Central sandbox

After installing Docker for Windows on your local machine, you can manually create a Docker-based Dynamics 365 Business Central container by running a script that pulls a container image from the Docker hub. From Command Prompt, you can execute the following command:

docker run -m 4G -e ACCEPT_EULA=Y -e UseSSL=N microsoft/bcsandbox:latest

This will create a Dynamics 365 Business Central container with the latest image available. If you want to create a sandbox with a particular localization (for example, IT), you can run the following command:

docker run -m 4G -e ACCEPT_EULA=Y -e UseSSL=N microsoft/bcsandbox:it

When executing this command, Docker pulls the container image from the Docker hub with all the dependent layers. This will take some time, and it requires at least 15 GB free space available on the disk. When the container provisioning is finished, you can see your running Docker containers by executing the following command:

docker ps

And this is the output of this command:
1.PNG

Other useful Docker commands to know are the following ones:

• docker images: Returns the container list
• docker pull: Docker image download (layers not in use)
• docker rmi: Removes a docker image via the ID
• docker run: Runs a docker image
• docker ps: Shows the running container
• docker rm: Removes a container ( –f, if it's running)
• docker inspect: Shows the content of a container (JSON)
• docker logs: Shows the execution log for a container
• Docker start/stop/restart <containername>
• Docker commit: Saves the current status of a stopped container as a new container image

In addition to using standard Docker commands, the NAV team provides an interesting PowerShell module called navcontainerhelper. This is a module from the PowerShell gallery that contains a number of PowerShell functions, which help running and interacting with NAV containers.

To use this module, start PowerShell ISE as administrator and run the following:

install-module navcontainerhelper -force

After installation, you can have a list of available commands by executing the following:

Get-command –Module navcontainerhelper

To create a new Dynamics 365 Business Central container, run the following script:

$imageName = "microsoft/bcsandbox:latest"
$navcredential = New-Object System.Management.Automation.PSCredential -argumentList "admin", (ConvertTo-SecureString -String "P@ssword1" -AsPlainText -Force)
New-NavContainer -accept_eula `
        -containerName "D365BC" `
        -Auth NavUserPassword `
        -imageName $imageName `
        -Credential $navcredential' '

This will create a locally hosted container based on the latest Dynamics 365 Business Central image with a specified name (D365BC) and NavUserPassword as authentication (with provided credentials):
2.PNG

This Powershell module is also useful for creating a new NAV container with your database backup:

$imageName = "microsoft/dynamics-nav:2018"
$navcredential = New-Object System.Management.Automation.PSCredential -argumentList "admin", (ConvertTo-SecureString -String "P@ssword1" -AsPlainText -Force)
New-NavContainer -accept_eula `
        -containerName "test" `
        -Auth NavUserPassword `
        -imageName $imageName `
        -Credential $navcredential `
        -licenseFile "https://www.dropbox.com/stefano/abcdefghijkl/my.flf?dl=1" `
        -additionalParameters @('--env bakfile="https://www.dropbox.com/s/abcdefghijkl/Demo%20Database%20NAV%20%2811-0%29.bak?dl=1"')

You can find more information about navcontainerhelper from the following links:
• https://github.com/Microsoft/navcontainerhelper
• https://blogs.msdn.microsoft.com/freddyk/tag/navcontainerhelper/

Steps for manually creating an Azure Container Instance-based Dynamics 365 Business Central sandbox

A Docker container can also be provisioned in the Azure cloud using Azure Container Instances. Azure Container Instances (ACI) provides a simple way to provision a container in Azure without installing everything. An ACI is a single container that starts in seconds and is billed by the time (number of seconds) you use it. You can create a new ACI directly from the Azure portal by selecting New | Azure Container Instance and then providing a resource group and the Docker image to start creating the container:
3.PNG

It is recommended to instead use the Azure Command Line Interface (CLI) that you can start directly from the top bar of your Azure portal:
4.PNG

From here, you can create a new ACI (container on Azure) by executing the following steps and commands:

  1. Create a resource group:
az group create --name D365BCRG --location WestEurope
  1. Create the container with the Dynamics 365 Business Central image you want:
az container create -g D365BCRG -n d365bc --image microsoft/bcsandbox:latest --os-type Windows --cpu 2 --memory 4 --ip-address public -e ACCEPT_EULA=Y USESSL=N ClickOnce=Y publicDnsName=d365bcpackt.westeurope.azurecontainer.io --dns-name-label d365bcpackt --ports 80 7046 7047 7049 8080

The DNS name (in this sample is d365bcpackt) must be unique to the region.
3. To monitor the container setup process, you can execute the following command. Note that this step is optional.

az container attach -g D365BCRG -n d365bcpackt

The user and the password for connecting to your just-deployed container can be found on the log using this command:

az container logs --resource-group D365BCRG --name d365bc

When the ACI provisioning is complete, you can connect to your Dynamics 365 Business Central container running on Azure using the public DNS name. More information about Azure container instances can be found at https://azure.microsoft.com/en-us/services/container-instances/.

If you found this article interesting, you can explore Dynamics 365 Business Central Development Quick Start Guide to understand the new Microsoft Extension model for development. Dynamics 365 Business Central Development Quick Start Guide is an ideal guide to Dynamics 365 Business Central and will help you get started with implementing and designing solutions for real-world scenarios.

Discover and read more posts from PACKT
get started