Friday, 7 July 2017

Installing / configuring Windows Server Containers (Docker) on Server 2016 Core

Docker and Microsoft formed an agreement back in 2014 to provide Docker technology to be integrated into Windows Server 2016.

Forenote: If you are running the host machine under ESXI you should ensure that you create a port group with promiscuous mode enabled in order to get Docker networking running in transparent mode!

Before enabling Docker we should ensure that the host system is up to date by running:

and select 'option 6'

or if you are on a non-core version:

wuauclt.exe /updatenow

restart the system and install the Container role with:

powershell.exe (Run as Administrator)

Enable-WindowsOptionalFeature -Online -FeatureName Containers
Install-Module -Name DockerMsftProvider -Repository PSGallery -Force

and the Docker powershell module with:

Install-Package -Name docker -ProviderName DockerMsftProvider

and restart the system with:

Restart-Computer -Force

Open up powershell again once the server has rebooted and we will now download an pre-made image from the Microsoft Docker repository - we can then add customisation to this and roll our own specialised version:

Install-PackageProvider -Name ContainerImage -Force

and proceed by installing the 'NanoServer' (this is a stripped down version of Server 2016)

docker pull microsoft/windowsservercore


Install-ContainerImage -Name WindowsServerCore

I prefer to use the native 'docker' commands since they can be applied to other operating systems as well.

And review our docker images with:

docker images

We can then run the container with:

docker run microsoft/windowsservercore

You'll notice the container will bomb out prety much straight away - this is because it simply loads cmd.exe and then quits. We need to specify the '-it' switch to run it in interactive mode - for example:

docker run -it --name windowscore microsoft/windowsservercore cmd.exe

Something better would be:

docker run -it --cpus 2 --memory 4G --network=<network-id> --name <container-name> --expose=<port-to-expose> -h <container-hostname> microsoft/windowsservercore cmd.exe

and a separate powershell window and verify it's running with:

docker ps

If all went well you should be presented with the command prompt (issue 'hostname' to verify the computer name) - now type exit and you will be dropped back powershell.

The docker container status is now classed as 'stopped' - in order to see all containers (including running and not running) issue:

docker ps -a

We can then either start the container again with:

docker start windowscore

or delete it with:

docker stop windowscore
docker rm windowscore

or attach to it with:

docker attach windowscore

You can also copy files from the Docker host to a container - for example:

docker cp C:\program.exe <container-name>:C:\Programs


Post a Comment