Windows Server 2016–Docker Container–dockerfile

Requirement is to configure docker image and run IIS based container to install/configure a website using DockerFile.

Here are the steps that needs to be done to implement the above requirement –

  1. Import microsoft/iis image from the Docker secure registry.
  2. Create the dockerfile to do the below activities –

    a. It installs .net features needed by the application.

    b. It copies application published data to the container.

    c. It creates and configures website with application pool.

    d. It sets .Net trust level.

    Note – Using this dockerfile, we can create container anywhere in any windows server 2016 environment.

    Here is the content of the dockerfile –


FROM microsoft/iis  

SHELL ["powershell"]

RUN Install-WindowsFeature NET-Framework-45-ASPNET ; \  

    Install-WindowsFeature Web-Asp-Net45

COPY Web C:\\inetpub\\wwwroot\\Web  

RUN Remove-WebSite -Name 'Default Web Site'  

RUN New-Website -Name 'abc' -Port 80 \  

    -PhysicalPath 'C:\inetpub\wwwroot\Web' -ApplicationPool '.NET v4.5'


RUN & c:\windows\system32\inetsrv\appcmd.exe set config /commit:WEBROOT /section:trust /level:Full


CMD ["ping", "-t", "localhost"]

Copy the above content into the text file and name it like dockerfile without any extension. Important note is that this file should not have any extension. Keep it in the same folder where you have kept the web folder (containing the published code of your site ‘abc’).

        3.  Built the image using the above dockerfile using the command for the location where you have kept the dockerfile – docker build –t [imageName] .

       4. Above command creates the image and you can access the list using the command – docker images


      5. Once image is created successfully, we need to create the container. It can be created using the command – docker run -d -p 80:80 [ImageName] ping -t localhost

It will create the container. You can get the list of running containers using the command – docker container ls


Complete flow of step 3,4 and 5 is given below –


Once all above steps are done successfully, you can browse your web application using any browser.

If you want to look inside the container, you can run the below commands and it will open the command prompt (cmd or PowerShell) inside the container and then you can using different commands to view the files –

1) For DOS command  – docker exec –I [ConatinerID] cmd


2) For PowerShell command – docker exec –I [ContainerID] powershell



———-End of Article———


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s