Category Archives: PowerShell

How I do Docker

Image result for docker

I had quite a few conversations about Docker this past week at Directions. And in every conversation, I basically said that my Docker usage is done with one-liners. So perhaps it would be smart to list all my one-liners. So here goes:

To install Docker for Windows on my Windows 10 PC, I use Chocolatey – with this simple PowerShell command:

choco install Docker-for-Windows

Then you need to install the brilliant NavContainerHelper with another PowerShell one-liner:

install-module navcontainerhelper -force

Now we’re ready to create a Docker container. Warning: This is a one-liner, but it’s a long one, you better put it in a .ps1 file, instead of copy’paste directly to a PowerShell prompt.

New-NavContainer -accept_eula -alwaysPull -imageName "microsoft/bcsandbox:dk" -containerName bcsandbox -licenseFile 'C:\license\my2018.flf' -memoryLimit 4G -updateHosts -shortcuts Desktop -includeCSide -assignPremiumPlan -auth NavUserPassword -myScripts @{"AdditionalOutput.ps1" = 'Copy-Item -Path (Join-Path $roleTailoredClientFolder "*office*.dll") -Destination (Join-Path $serviceTierFolder "Add-ins\Office")'}

Since this is quite a long command, let me break it down into the important parameters:

accept_eula Because where’s the fun without an EndUserLicenseAgreement to accept
alwaysPull Make sure you have the latest version of the image from Microsoft.
imageName What image your container should be based on.
-containerName This is the “computer name” your container will get. This is the name you can PING, this is the name you’ll use in the browser address bar and in Visual Studio Code to access the container.
licenseFile An URL or direct file path to an FLF license file to be imported to the container.
memoryLimit Limit the memory used by the container.
updateHosts Update the hosts file with an entry for the imageName.
shortCuts Create shortcuts for access to the container.
includeCSide Because we still need CSide
assignPremiumPlan Hey, I need a Premium experience
auth NavUserPassword Create a NavUserPassword access. The first thing happening is a prompt to enter a user and password. It looks like it’s asking for you login, but the dialogue is actually asking for a user and password combo.

The last command is just something I need because some Office DLLs are missing in the add-ins folder (to be available for DotNet), you properly don’t need it unless you’re using DotNet like me:
myScripts @{“AdditionalOutput.ps1” = ‘Copy-Item -Path (Join-Path $roleTailoredClientFolder “*office*.dll”) -Destination (Join-Path $serviceTierFolder “Add-ins\Office”)’}

Speaking of DotNet, sometimes I need to add extra DotNet DLLs, that’s done with this one-liner:

Copy-FileToNavContainer -localPath c:\DLLs\*.dll -containerPath "C:\Program Files\Microsoft Dynamics NAV\130\Service\Add-ins" -containerName bcsandbox

Again a great feature of NavContainerHelper, simply copies files from my local machine into the container.

Sometimes,  I need to restart the container, also done with NavContainerHelper:

Restart-NavContainer -containerName bcsandbox

Hope this helps a bit to lean but great Docker and Business Central/NAV experience.

 

Move my Chocolatey apps to another PC

Ahh, I have always enjoyed meta programming, so when I was thinking about how to get my Chocolatey apps from one PC to another, the choice was easy: A small Powershell command to create a Powershell script to install my apps somewhere else.

It’s a oneliner that loops the installed Chocolatey apps via the “choco list” command and generates a list of strings.

choco list -lo -r -y | % { "choco install $($_.SubString(0, $_.IndexOf("|"))) -y" } | Out-File Install.ps1

This is how the output looks on my machine:

choco install 7zip -y
choco install 7zip.install -y
choco install beyondcompare -y
choco install chocolatey -y
choco install chocolatey-core.extension -y
choco install chocolateygui -y
choco install docker-for-windows -y
choco install DotNet4.5.2 -y
choco install DotNet4.6.1 -y
choco install Firefox -y
choco install git -y
choco install git.install -y
choco install httrack.app -y
choco install KB2919355 -y
choco install KB2919442 -y
choco install openra -y
choco install PowerBI -y
choco install python3 -y
choco install resharper-platform -y
choco install sabnzbd -y
choco install sharpkeys -y
choco install sublimetext3 -y
choco install visualstudiocode -y
choco install vlc -y
choco install vscode -y
choco install win32diskimager -y
choco install win32diskimager.install -y

Quite easy to setup a new PC, thanks to the power of PowerShell and Chocolatey 🙂