How to get started with IIS on Docker
Tags: docker, microservices, devops
Published: 2020-06-18 06:38:17

In one of our customer projects, we have a mixed Swarm Cluster with Linux and Windows nodes. On the Windows nodes, we run a bunch of IIS containers that run several web applications. In this blog post, I want to showcase you how easy it is to deploy a Website on IIS in a Docker Container.

The Internet Information Services (IIS) is a web server for Windows Server. You can find more information about it on the [official Web Site](https://www.iis.net/). Microsoft already provides a large list of Docker Images for IIS. You can find more information on [Docker Hub](https://hub.docker.com/_/microsoft-windows-servercore-iis) and the Dockerfiles for the images in the [GitHub Repo](https://github.com/microsoft/iis-docker).

##The Code

A web server allows you to access files from a folder via HTTP requests. For IIS the default folder is `C:\inetpub\wwwroot`. This means, that you need to add the content of your website to this folder. The screenshot below shows an example folder structure. There you can see that all the content of the website is in the `wwwroot-folder`.

![IIS Website folder structure](https://dev-to-uploads.s3.amazonaws.com/i/zbuabdfk1rdu5h9rgv2i.png)

Besides the content of your website, all you need is a Dockerfile with only two lines of code:

```
FROM mcr.microsoft.com/windows/servercore/iis:windowsservercore-ltsc2019

ADD wwwroot /inetpub/wwwroot/
``` 

With the Dockerfile in place, open this folder in PowerShell. To build the container image, execute the following command:

```
docker build -t iis-website .
```

After building the image, you can run the container:

```
docker run -p 80:80 iis-website
```

Now you can access the website in your favorite browser with the URL `http://localhost`. Be aware, that it can take several seconds for Windows Containers to start. This means you have to wait a bit until the website appears in your browser.

![Screenshot of the Website running on IIS in a Docker Container](https://dev-to-uploads.s3.amazonaws.com/i/lq5wzif7wzsku5yafi5p.png)

You can extend this approach, to also add all the required configurations to the `Dockerfile`. This allows you to track all the changes in your version control system. This enables you to add the building, testing, and deployment to your CI/CD pipeline.

## Summary
In this post, I showed how easy it is to run a website on IIS in a Docker container. By specifying everything in code you can add the configurations and all the needed files to your version control system. This enables you to integrate it into a CI/CD pipeline, one piece of the DevOps puzzle.

## More Information
I didn't cover how to get started with Docker on Windows in this post. You can find more information about that in the official documentation:

* [Docker for Windows](https://docs.docker.com/docker-for-windows/), especially look at the *Switch between Windows and Linux containers*
* [Install Docker on Windows Server](https://docs.microsoft.com/en-us/virtualization/windowscontainers/deploy-containers/deploy-containers-on-server)

For more information about IIS on Docker, you can head over to the following links:

* [IIS Container Images on Docker Hub](https://hub.docker.com/_/microsoft-windows-servercore-iis)
* [IIS Docker Images on GitHub Repo](https://github.com/microsoft/iis-docker)

Originally posted on the [56K.Cloud Blog](https://blog.56k.cloud) by [Jochen Zehnder](https://twitter.com/elft3r)

## Find out more about 56K.Cloud
We love Cloud, IoT, Containers, DevOps, and Infrastructure as Code. If you are interested in chatting connect with us on [Twitter](https://twitter.com/56kcloud) or drop us an email: info@56K.Cloud. We hope you found this article helpful. If there is anything you would like to contribute or you have questions, please let us know!