Run your first Windows Container on your Windows 10

Run your first Windows Container on your Windows 10

Windows 10 now comes with container feature available to pro and enterprise version. To get started with containers on windows 10, please make sure below pre-requisits are met.

Pre-requisites

Let's ensure we have pre-requisites installed before we get started with docker cli and container installation. If you already have below items install, you can skip them and proceed the setup.

Windows 10 now comes with container feature available for developers and devops engineers to start using Docker containers in their local environment. To enable containers for windows 10, execute below command.

Enable-WindowsOptionalFeature -FeatureName containers -Online -all

NOTE: Upon installation you will be prompted for rebooting your system after container feature is enabled. It is recommended that you select yes to reboot your system.

Install Docker CLI

Now we will go ahead and download latest docker cli by using Chocolate package management tool.

Once you have choco installed, go ahead and open PowerShell as an administrator and execute below command.

choco install docker

You will be asked to say yes or no. Go ahead and continue with the interactive installation process by pressing Y. The output should look like below if the installation was successful.

windows-10-docker-cli-installation

Now that you have docker cli installed, you are now ready to run your first docker container.

Installing Docker Enterprise Edition (EE)

To install Docker EE on Windows 10, please make sure above setup is successfully completed. To get started go ahead and execute below commands from elevated PowerShell console.

To go Downloads folder of your current user.

cd ~\Downloads

Download Docker Enterprise Edition from online

Invoke-WebRequest -UseBasicParsing -OutFile docker-18.09.3.zip https://download.docker.com/components/engine/windows-server/18.09/docker-18.09.3.zip

NOTE: In this tutorial I am using docker 18.09.3 version. This may change in future. You can follow updated document from here

Extract docker package.

Expand-Archive docker-18.09.3.zip -DestinationPath $Env:ProgramFiles -Force

Execute below script to setup and start docker

# Add Docker to the path for the current session.
$env:path += ";$env:ProgramFiles\docker"

# Optionally, modify PATH to persist across sessions.
$newPath = "$env:ProgramFiles\docker;" +
[Environment]::GetEnvironmentVariable("PATH",
[EnvironmentVariableTarget]::Machine)

[Environment]::SetEnvironmentVariable("PATH", $newPath,
[EnvironmentVariableTarget]::Machine)

# Register the Docker daemon as a service.
dockerd --register-service

# Start the Docker service.
Start-Service docker

Test your docker setup by executing below command.

docker container run hello-world:nanoserver

Running your first docker container

In this example, I will be using nanoserver image from docker hub to run IIS application.

  1. Let's first check if we have any docker images pulled from docker hub. Based on above setup for docker you should have a hello-world docker image pulled from docker hub.
docker images
  1. Let's pull new docker image from docker hub to run nanoserver with IIS configured.
docker pull nanoserver/iis

Your final output should look like below.
docker-iis-nanoserver-for-windows-container
3. After we have pulled latest image from docker hub, lets run our first windows container by executing below command.

docker run --name nanoiis -d -it -p 80:80 nanoserver/iis

After it will return a container id that you can use to check container status, configuration, etc.
4. Check our first container status by executing below command.

docker ps -a -f status=running

Status output:
docker-iis-nanoserver-for-windows-container-status
5. Now let's get the IP address of our container to access it from the browser.

docker inspect -f "{{ .NetworkSettings.Networks.nat.IPAddress }}" nanoiis
  1. Copy the IP address that was returned in the PowerShell console and browse it in internet explorer.
    docker-iis-nanoserver-for-windows-container-iis-browser

In my case I received 172.19.231.54. Yours maybe different.

This is it! You have ran your first windows container on your windows 10 machine. Thank you for following this tutorial.