Getting started with containers and Docker on Windows Server 2016 Technical Preview 5
28 Apr 2016 in Docker | Microsoft AzureThe Technical Preview 5 of Windows Server 2016 has been released yesterday, and it comes with a lot of new cool things for Windows containers and Docker !
To get started with this new preview, you have two solutions:
- Download it from this page and run it where you want.
- Deploy a new VM in Azure from the MarketPlace
I have chosen the second option, as it is simple and fast. Just search for Windows Server 2016 in the Azure MarketPlace and you’re done:
Once you are connected on your machine, you need to configure it to be a container host. It can be done with a few steps:
Install-WindowsFeature Containers
Once installed, you need to restart the machine using:
New-Item -Type Directory -Path 'C:\Program Files\docker\'
Invoke-WebRequest https://aka.ms/tp5/b/dockerd -OutFile $env:ProgramFiles\docker\dockerd.exe
Invoke-WebRequest https://aka.ms/tp5/b/docker -OutFile $env:ProgramFiles\docker\docker.exe
[Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\Program Files\Docker", [EnvironmentVariableTarget]::Machine)
The commands above create a new Docker folder in Program Files and download the docker deamon and client binaires in this directory. The last one adds the directory in the Path environment variable. The Docker deamon now supports an option to register it as a service on the machine:
dockerd --register-service
To start the docker service use:
Start-Service docker
Now, you need to download the base image for Docker containers on Windows. You can do it with the following commands:
Install-PackageProvider ContainerImage -Force
Install-ContainerImage -Name WindowsServerCore
Restart the Docker service:
Restart-Service docker
And your done!
docker info
You can also get the list of available images on your system by typing:
docker images
As you can see, an image named windowsservercore is available, but it does not have the “latest” tag. To tag it, type:
docker tag windowsservercore:10.0.14300.1000 windowsservercore:latest
You can run your first container with the following command:
docker run -it windowsservercore cmd
It will run a new container in interactive mode and execute cmd inside the container:
Type exit
to leave the container.
As announced by Docker, it is now possible to write Dockerfile for Windows-based images and you can start to push/pull Windows images to and from the Docker Hub. Some example of Windows-based Dockerfile are available on GitHub: https://github.com/Microsoft/Virtualization-Documentation/tree/master/windows-container-samples/windowsservercore
For example, you can use this Dockerfile to create an image that will allow to run IIS in a container:
# This dockerfile utilizes components licensed by their respective owners/authors.
FROM windowsservercore
MAINTAINER [email protected]
LABEL Description="IIS" Vendor="Microsoft" Version="10"
RUN powershell -Command Add-WindowsFeature Web-Server
CMD [ "ping localhost -t" ]
Save this Dockerfile in an empty directory. Open a PowerShell window in this directory and build the container image with the docker build
command:
docker build -t yourimagename .
Once the image is built, login to your Docker Hub account using the docker login
command:
And push the image using the docker push
command:
Same experience than Docker with Linux containers ! It’s awesome !
Here are some resources that you may be interested in to go deeper in Windows Containers:
- Windows Containers overview: https://msdn.microsoft.com/en-us/virtualization/windowscontainers/about/about_overview
- The Containers Channel on Channel9: https://channel9.msdn.com/Blogs/containers
- Windows Server Containers – Quick Start using Docker: https://msdn.microsoft.com/en-us/virtualization/windowscontainers/quick_start/manage_docker
- Dockerfile reference on Windows: https://msdn.microsoft.com/en-us/virtualization/windowscontainers/docker/manage_windows_dockerfile
- Windows Dockerfile samples on GitHub: https://github.com/Microsoft/Virtualization-Documentation/tree/master/windows-container-samples/windowsservercore