Docker: Windows containers on Windows host
For more than one year Windows developers can hear about Docker stuff. But after few sentences how docker is great there is one important sentence:
Nowadays we can run only docker containers on Linux. There is no way to run Windows containers.
Docker engine for Windows server requires Windows Server 2016. You can try preview to test it.
♪ Few days ago above statements ♪ outdoor. Are you ready to run it on your Windows 10?
To have fun with Windows containers you need Windows 10 Insider Preview. I describe how to get it in How to setup Bash and Ubuntu on Windows – step by step guide
After you have it check out if you already install version 14352 or greater.
The second way is to install Windows Server 2016 technical preview-as I remember from version 4 containers are available.
Having one of above versions we are ready to deploy a simple Hyper-V container.
Small tip before we start
Most commands we will run in elevated PowerShell. I usually, forget to run it. But few months ago I described how to run
sudo command in Windows. Using
sudo ♪ I can run ♪
sudo powershell and use
up arrowthis is rerun command as admin.
Enable Hyper-v and containers feature
If you didn’t play with Hyper-V on your machine before, this step is most complicated.
To enable HYPER-V in modern laptops usually we have to access bios. For example in Lenovo, I have to find a special hidden button to enter BIOS. Tricky!
When you are ready, start PowerShell as Administrator and run:
Enable-WindowsOptionalFeature -Online -FeatureName containers –All Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V –All
The first command will install containers feature and the second Hyper-V stuff.
Now reboot if needed 🙂
Containers needs Docker. To install it we can run following commands:
$dockerDir = "$env:ProgramFilesdocker" New-Item -Type Directory -Path "$dockerDirdocker" Invoke-WebRequest https://aka.ms/tp5/b/dockerd -OutFile $dockerDirdockerd.exe Invoke-WebRequest https://aka.ms/tp5/b/docker -OutFile $env:ProgramFilesdockerdocker.exe [Environment]::SetEnvironmentVariable("Path", $env:Path + ";$dockerDirDocker", [EnvironmentVariableTarget]::Machine) $env:Path = $env:Path + ";$dockerDirDocker"
First three lines will download “special” Docker.
Last two commands will add docker path for future and current session use.
Now we can install Docker as a service (maybe Daas will be next famous shortcut?) and start it:
dockerd --register-service Start-Service Docker
Base image – NanoServer
We are ready now to install base container image: nanoserver. Nanoserver is the “smallest” version on Windows Server 2016. It doesn’t have GUI 🙂
Few simple commands and we are ready:
Install-PackageProvider ContainerImage -Force Install-ContainerImage -Name NanoServer Restart-Service docker
Attention: If you have a problem with running commands run
Set-ExecutionPolicy Bypass -scope Process to change execution policy in current PowerShell process.
To check if everything is OK, invoke:
you should see something like:
REPOSITORY TAG IMAGE ID CREATED SIZE nanoserver 10.0.14300.1010 9db95268a387 9 weeks ago 817.1 MB
Now we are ready to deploy container. At first, we need to mark our image as
docker tag nanoserver:10.0.14300.1010 nanoserver:latest
And our final commands are:
docker pull microsoft/sample-dotnet docker run --isolation=hyperv --rm microsoft/sample-dotnet
Hurrah, we just run our first container. To be sure that we are running Windows not Linux try another one:
docker run --isolation=hyperv --rm -it nanoserver powershell
Which will run
powershell on nanoserver image. For example use
lsand find out what directories you have on Nano Server
Next time I will show how to deploy normal IIs and old .Net version (like 3.5 or 4.5) on Docker images . Follow me on Twitter, Facebook or RRS.
Piotr-IT Expert at mBank S. A.