How To Create A Windows Containers Image Using Dockerfile

In this article, I’ll show you how I create a Windows Containers Image using Dockerfile which allows me to create a custom Container using a Runsheet of cmdlets.

Why use Dockerfile? The container Image Is saved as a code and it’s always using the latest Container build compare to using a commit Image.

In this example, I’ll create a Container Image with Windows IIS Installed on Windows Server Core 2016.

In the code below, I’ll use a Windows Core 2016, Install IIS and add HTML page to the default IIS site.

FROM microsoft/windowsservercore

RUN dism.exe /online /enable-feature /all /featurename:iis-webserver /NoRestart

RUN echo "Hello World - Dockerfile" > c:\inetpub\wwwroot\index.html

CMD [ "cmd" ]

Once the code Is done, I’ll save the file without file extension using “” as seen below.

"Dockerfile"

Once saved In a folder (I called my folder IIS) I’ll run the command below to create the Image

docker build -t iis .

Important – Don’t forget the . At the end

When done, I’ll check that the image was created

Docker images

Next, I’ll create a new Container with the new Image

Docker run --name test01 -it microsoft/iis cmd

Leave a Reply