How To Configure Docker On Windows

I recently started playing around with Docker on Windows and one of the first hurdles was how to configure Docker on Windows. Since I’m completely new to containers I’m going to share what I  figured out in case it can help someone else.

I followed this quick start from Microsoft which actually works very well. I used the server version but heads up if you want to use Docker with Windows 10. Docker requires Hyper-V and if you use VMWare Workstation you can’t have both installed at the same time.

There is a ton of information about Docker for Windows on their website but I wanted to highlight a few practical bits which most people would need to get started.

How to configure Docker on Windows

By default the Docker executables are located in “C:\Program Files\Docker” and its data is stored in %programdata%\docker. You’ll see the default container, image and configuration directories are here as well. When you install Docker it will be running with default values. To change the defaults you have to create a configuration file %programdata%\docker\config\daemon.json. The full configuration reference is here. The part I was interested in was changing the location where containers and images are stored to get them of my OS disk. The setting turned out to be the “graph” settings.

{"data-root": "D:\\Data\\Docker\\"}

Take note this changes the root directory for Docker data, not just the containers and images.

How to get clean Windows  Images

If you ran the quick start mentioned earlier, you’ll see it was running a container using the Nano Server image with a sample application. I wanted to firstly get an empty Windows image to play around with and secondly I wanted to run full .NET applications which require a Server Core image. The command to pull down the images from the Docker Hub are:

docker pull mcr.microsoft.com/windows/servercore:1903

docker pull mcr.microsoft.com/windows/nanoserver:1903

You can explore the Docker Repository to see which other images are available, link.

Exploring The Container Environment

I wanted to see what you get in a container and play around a bit. To start a new container interactively run:

docker run -i mcr.microsoft.com/windows/nanoserver:1903

docker run -i mcr.microsoft.com/windows/nanoserver:1903 powershell.exe

In the second instance the container will run PowerShell.exe after it started or you just run it from the command prompt yourself. In a future post I’ll dive into the isolation and integration between the host and container in more detail. For now I could see you get your own filesystem, network, installed windows features and registry but you get the users from the host.

Note: These Docker Hub repos did not maintain a “latest” tag, you have to specify the image tag for example 1903. The host Windows OS version can’t be lower than the container version. When you run a container that is an older version than the host it will use Hyper-V isolation. I was on Windows 10 version 1909 and I was able to run NanoServer 1903 and Server Core ltsc2019 but not 20H2 more info here.

Francois Delport