Skip to content

Instantly share code, notes, and snippets.

@mustafaakin
Last active May 31, 2023 05:28
Show Gist options
  • Save mustafaakin/0cfbc1b4bb346a05a615 to your computer and use it in GitHub Desktop.
Save mustafaakin/0cfbc1b4bb346a05a615 to your computer and use it in GitHub Desktop.
Running Windows Server 2k16 with Docker under Linux, KVM or Virtualbox

Are you let down when you saw there is no guide to use Windows Server 2016 under *nix environments? I really loved Microsoft when I heard they are working on Windows containers, but when this week has arrived, it was sad to see that installation requirements were Windows and HyperV. But actually it is not. You just have to modify the VHD file a bit with nicer tools and execute the already available script in the downloaded VM. I will assume you are running a decent version of Linux and accepted EULA and all the legal stuff that I do not care.

1. Getting the required tools:

$ sudo apt-get install qemu-kvm virt-manager // or virtualbox, but we need qemu-kvm for image manipulation
$ sudo apt-get install qemu-utils libguestfs-tools // image manipulation tools

2. Downloading files

WS2016 TP3 VHD image

Be careful, the VHD image is around 6.3 GB zipped, 13 GB unzipped VHD.

$ wget http://aka.ms/containerhostvhd -O host.zip
$ unzip host.zip
$ // outputs windowsserver_en-us_tp3_container_vhd.vhd

NSSM: (Non Sucking Service Manager)

Manages services, does not seem to be an official MS tool but, it was included in the official script.

$ wget http://nssm.cc/release/nssm-2.24.zip
$ unzip nssm-2.24.zip

unattend.xml

You have to type this file, it is in the gist. If you want, you can modify the password (beware, 2 instances).

3. Modifiyng the VM Image

First, we convert VHD image to QCOW2 format. Beware it takes a lot of time, even on an SSD. Then, we mount it using the tools we have. Reason we use sudo is that we mount it through KVM to make it faster and more reliable. Then we need to copy the attend.xml to C:/ and nssm.exe to System32 folders.

$ qemu-img convert -f vpc -O qcow2 windowsserver_en-us_tp3_container_vhd.vhd ws2016_core.qcow2
$ mkdir mnt
$ sudo guestmount -a ws2016_core.qcow2 -i mnt
$ sudo cp unattend.xml mnt/
$ suco cp nssm-2.24/win64/nssm.exe mnt/Windows/System32/
$ sudo umount mnt/

4. Creating a new VM

You have to create a new virtual machine, you can do it with VirtManager or VirtualBox.

virt-manager

  1. Create a new Virtual Machine
  2. Import existing disk image, Forward
  3. Provide existing storage path, Browse
  4. Browse Local
  5. Find ws2016_core.qcow2, and Open
  6. OS Type: Windows
  7. Version: Microsoft Windows Server 2008 or later
  8. Adjust memory and RAM (give as much as you can)
  9. Finish

virtualbox

My VirtualBox did not support the qcow2 image I had, we may need to convert it to VDI (virtual disk image) so it plays with it nicer. You can do it via:

$ qemu-img convert -f qcow2 -O vdi container_host.qcow2 container_host.vdi
  1. New
  2. Name whatever you like
  3. Type: Microsoft Windows, Version: Windows 2012 (64 bit)
  4. Memory: Be generous, at least 2GB
  5. Use an existing virtual drive
  6. Browse icon, find the vdi image we had
  7. Finish (optionally change CPU count from settings to run it faster)

5. Running the VM

When you run VM via virt-manager or virtualbox, you will see some Windows logo and then you will see a command window. Maximize it and execute the powershell, and execute the already available script we have. I know this could be automated with unattend.xml, but I am no MS expert

C:\Users\Administrator> powershell
PS C:\Users\Administrator> cd /
PS C:\> .\Install-ContainerHost.ps1

It will ask you to type DockerPath. And you need to write http://aka.ms/ContainerTools and it will download docker.exe from web and place it to System32 folder.

6. Running Docker commands in Windows

You will see the following as a result:

ScreenShot

Happy containerizing!

Mustafa Akın mustafa91 at gmail

<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
<servicing></servicing>
<settings pass="generalize">
<component name="Microsoft-Windows-PnpSysprep" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<PersistAllDeviceInstalls>true</PersistAllDeviceInstalls>
<DoNotCleanUpNonPresentDevices>true</DoNotCleanUpNonPresentDevices>
</component>
<component name="Microsoft-Windows-Security-SPP" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SkipRearm>1</SkipRearm>
</component>
</settings>"
<settings pass="specialize">
<component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<AutoLogon>
<Password>
<Value>MustafaMustafa91</Value>
<PlainText>true</PlainText>
</Password>
<Enabled>true</Enabled>
<LogonCount>999</LogonCount>
<Username>Administrator</Username>
</AutoLogon>
<ComputerName>*</ComputerName>
</component>
<component name="Microsoft-Windows-TerminalServices-LocalSessionManager" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<fDenyTSConnections>false</fDenyTSConnections>
</component>
<component name="Microsoft-Windows-TerminalServices-RDP-WinStationExtensions" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<UserAuthentication>0</UserAuthentication>
</component>
<component name="Networking-MPSSVC-Svc" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<FirewallGroups>
<FirewallGroup wcm:action="add" wcm:keyValue="RemoteDesktop">
<Active>true</Active>
<Profile>all</Profile>
<Group>@FirewallAPI.dll,-28752</Group>
</FirewallGroup>
</FirewallGroups>
</component>
</settings>
<settings pass="oobeSystem">
<component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<OOBE>
<HideEULAPage>true</HideEULAPage>
<HideLocalAccountScreen>true</HideLocalAccountScreen>
<HideWirelessSetupInOOBE>true</HideWirelessSetupInOOBE>
<NetworkLocation>Work</NetworkLocation>
<ProtectYourPC>1</ProtectYourPC>
</OOBE>
<UserAccounts>
<AdministratorPassword>
<Value>MustafaMustafa91</Value>
<PlainText>True</PlainText>
</AdministratorPassword>
</UserAccounts>
</component>
<component name="Microsoft-Windows-International-Core" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<InputLocale>en-us</InputLocale>
<SystemLocale>en-us</SystemLocale>
<UILanguage>en-us</UILanguage>
<UILanguageFallback>en-us</UILanguageFallback>
<UserLocale>en-us</UserLocale>
</component>
</settings>
</unattend>
@alanyih
Copy link

alanyih commented Aug 29, 2015

typo:
> 3. Modifiyng the VM Image
>..
> $ suco cp nssm-2.24/win64/nssm.exe mnt/Windows/System32/

@katzurki
Copy link

The aka.ms link no longer redirects to the static download. This should: http://bit.do/2016kcontainervhd

(8.2Gb from a MS server; filename 17763.379.amd64fre.rs5_release_svc_refresh.190312-0539_server_serverdatacentereval_en-us.vhd, not zip!)

@katzurki
Copy link

katzurki commented May 14, 2019

Oh, 2015. Hehe. Well, still a top search result and I [soon hope to find out] a working guide. Cheers.

(I think you have a typo in "attend.xml" in Modifying the VM—unattend.xml, surely?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment