Windows Server 2016

Managing Windows Server Containers with PowerShell: Creating a New Container

If you are going to work with Windows Server Containers at scale, then you will probably use a management solution, such as Docker and Mesosphere. However, Microsoft has provided us with a great set of PowerShell cmdlets to deploy and manage Windows Server Containers. In part one of this three-part series, we’ll look at how we can use these cmdlets to manage and deploy Windows Server Containers in this article.

This post is part of a series:

  • Part 1: Container file locations and creating new containers
  • Part 2: Administration of containers and creating a new container image (coming soon)
  • Part 3: Deploying container-based services on the network (coming soon)

A Note about File Locations

There are several different file locations that you want to know about. In Technical Preview 3 (TPv3) of Windows Server 2016, the container image repository is kept on the C: drive of the VM host. In a future release, we should expect that a capability that lets us deploy a highly available centralized repository. You can find the local repository at C:\ProgramData\Microsoft\Windows\Hyper-V\Container Image Store.

Any new container is created in C:\ProgramData\Microsoft\Windows\Hyper-V\Containers. There you will find there files and one directory named after the GUID of the container. This is also where you will find new file types for Hyper-V:

Sponsored Content

What is “Inside Microsoft Teams”?

“Inside Microsoft Teams” is a webcast series, now in Season 4 for IT pros hosted by Microsoft Product Manager, Stephen Rose. Stephen & his guests comprised of customers, partners, and real-world experts share best practices of planning, deploying, adopting, managing, and securing Teams. You can watch any episode at your convenience, find resources, blogs, reviews of accessories certified for Teams, bonus clips, and information regarding upcoming live broadcasts. Our next episode, “Polaris Inc., and Microsoft Teams- Reinventing how we work and play” will be airing on Oct. 28th from 10-11am PST.

  • .VHDX: This is a virtual hard disk that contains the unique content of the container.
  • .VMCX: The VMCX file is the configuration of the container. This is the new binary format file, offering better performance for large scale deployments. The binary format also prevents some of the silly XML editing that was done by some in the past.
  • .VMRS: This is the runtime state of the container.
  • Hives: A hives folder can be found tucked away in a directory named after the GUID of the container. There you will find some registry hives for the container.
Browsing the files and folders of a Windows Server Container (Image Credit: Aidan Finn)
Browsing the files and folders of a Windows Server Container (Image Credit: Aidan Finn)

Every new container that you create will be based on a container image of an operating system. In TPv3, we get a container image for Windows Server Core that is imaginatively called WindowsServerCore. You can find this image in C:\ProgramData\Microsoft\Windows\Images. If you dive a little deeper, you will find a familiar folder structure for Windows Server.

The WindowsServerCore container image (Image Credit: Aidan Finn)
The WindowsServerCore container image (Image Credit: Aidan Finn)

PowerShell Cmdlets for Managing Containers

The first time that I worked with Windows Server Containers I had no access to documentation. I had watched a session from Microsoft Ignite 2015 on the theory of containers, but that was it. I knew that Containers was managed using PowerShell, so I did what most PowerShell admins will do — I ran Get-Command to discover what cmdlets are available for managing containers:

Get-Command -Module Containers

The list of cmdlets available for containers in Windows Server 2016 Technical Preview 3 (Image Credit: Aidan Finn)
The list of cmdlets available for containers in Windows Server 2016 Technical Preview 3 (Image Credit: Aidan Finn)

Creating the First Container

All containers are based on a container image for the desired operating system. You can find container images by running Get-ContainerImage. This allowed me to discover the container image WindowsServerCore.

Containers will be networked using a virtual switch that runs in the VM host. Find the virtual switch with Get-VMSwitch. The default (from New-ContainerHost.ps1) switch is called Virtual Switch.

To create a new container, you will use New-Container. I want to create a container from WindowsServerCore that is connected to the default virtual switch:

$Container = New-Container -Name Test1 -ContainerImageName WindowsServerCore -SwitchName "Virtual Switch"

That cmdlet will take about one to two seconds to run! Yes, you just deployed a new isolated service environment in one to two seconds! There are other options that you can use to configure the startup memory of the container and the storage path that you might find useful.

Note that it’s useful to store the resulting pointer to the container in a variable. You will use that variable several times when configuring a new container. For example, you will want to start the container:

Start-Container $Container

And then you will want to view the properties and status of the container:
$Container | fl *

Note that you can get the ID attribute of the container to discover which files in C:\ProgramData\Microsoft\Windows\Hyper-V\Containers are owned by a specific container:
$Container.Id

You could also run:
(Get-Container Test1).Id

You’ve now learned where container files are stored, how to create a container, how to start a container, and how to query the status and attributes of a container. In the next article, we will look at remote administration and installing software to create a new container image.

Related Topics:

BECOME A PETRI MEMBER:

Don't have a login but want to join the conversation? Sign up for a Petri Account

Register
Comments (0)

Leave a Reply

Aidan Finn, Microsoft Most Valuable Professional (MVP), has been working in IT since 1996. He has worked as a consultant and administrator for the likes of Innofactor Norway, Amdahl DMR, Fujitsu, Barclays and Hypo Real Estate Bank International where he dealt with large and complex IT infrastructures and MicroWarehouse Ltd. where he worked with Microsoft partners in the small/medium business space.
External Sharing and Guest User Access in Microsoft 365 and Teams

This eBook will dive into policy considerations you need to make when creating and managing guest user access to your Teams network, as well as the different layers of guest access and the common challenges that accompany a more complicated Microsoft 365 infrastructure.

You will learn:

  • Who should be allowed to be invited as a guest?
  • What type of guests should be able to access files in SharePoint and OneDrive?
  • How should guests be offboarded?
  • How should you determine who has access to sensitive information in your environment?

Sponsored by: