Introduction to Windows Containers

 

I am very trhilled to write this article as i am a huge fan of Docker and PowerShell so, both of the two worlds are starting to works smoothly on Windows 2016 Server TP3. TP3 means Technical Preview 3, so for the moment, keep in mind that Windows Containers are not production ready, unlike PowerShell 5 which is.

I won’t do the presentation for Docker, if you don’t have heard about them, i sguggest you to opens qwant.com and read about it. It will help you in IT, because this is clearly THE thread everyone is talking about for 2 years at least.

First of all, let’s download a wim image of DataCenter Core server packaged for Windows Containers here: http://aka.ms/ContainerOSImage

Now, during the download, let’s have a look about how to run Windows Containers on Windows Server 2016 TP3.

Install-WindowsFeature -Name Containers

01

The Feature is now installed, let’s take a look at what we have in the PowerShell module associated, because there is no GUI tools at the moment to manage your Containers, and this is awesome!

Get-Command -Module Containers

02

As you see, ce can do many intresting things 😀

Let’s have a closer look and start using a container. In order to do this we’ll need at first install the container OS Image.

Install-ContainerOSImage -WimPath C:\Containers\CBaseOs_th2_release_10514.0.150808-1529_amd64fre_ServerDatacenterCore_en-us.wim

This will enable the DataCenterCore image to be available for our containers, you can verify that using

Get-ContainerImage

04Now that the image is available, let’s build our container 🙂

$ContainerImage = Get-ContainerImage | ? Name -eq 'WindowsServerCore'
New-Container -Name PwrShell -ContainerImage $ContainerImage -MemoryStartupBytes 32MB

05The Containet is now created, but not started, let’s use Start-Container to correct this

Start-Container
Get-Container PwrShell

06

Ok, let’s add network connectivity to our Container 🙂

I noticed Add-ContainerNetworkAdapter cmdlet, so let’s have a look.

Add-ContainerNetworkAdapter -ContainerName PwrShell -Name Nic1
Get-Container PwrShell

07Ok the network interface is added, but how can we get info about it ? The good old Get-Member to the help !

Get-Container PwrShell | gm

08

Get-Container PwrShell | Select -ExpandProperty NetworkAdapters

If you’re familiary with Hyper-V theses lines will get common for you

09So it seems a virtual switch is needed if we want to route traffic to/from our container !

New-VMSwitch -Name Internal -SwitchType Internal

11

After doing a Get-Help Set-ContainetNetworkAdapter, i got the feeling that the vswitch needed to be declarated when the Network adapter is added to the container. So let’s remove the previous one a create a new.

Remove-ContainerNetworkAdapter -ContainerName PwrShell

And add a new one with the correct switch and a dynamic Mac address… and connect it to the internal network !

Add-ContainerNetworkAdapter -ContainerName PwrShell -Name Nic1 -SwitchName Internal -DynamicMacAddress
Connect-ContainerNetworkAdapter -ContainerName PwrShell -SwitchName Internal

Everything is OK ?

Get-Container | Get-ContainerNetworkAdapter

12

And now, connect it 🙂

$Container = Get-Container -Name PwrShell
Enter-PSSession -ContainerId $Container.ContainerId -RunAsAdministrator

13

Once again, administrators will have to go deeper inside their command line tools because everything is about PowerShell to manage containers. Which is fine for me ! Another thing, There is a lot of Hyper-v behind the scene, i don’t know if it’s a good thing or not, but this isn’t totally Docker like as i’d love too. We’re talking about a full OS at the moment and i hope one day, we’ll be able to launch applications 😀

Anyway, this is again a good move from Microsoft, like they have in the past 18 months 🙂