blog-post-1

Getting started with Windows containers

I started using docker a year ago. Since then I run so many technologies from mongo db to aspnet core app using it on Linux. Now It's time to try what can be done with docker  on Windows. In this post I will try to compare developer and operational experience with docker on Linux vs Windows. 

Getting started

To get started it is necessary to have the latest Windows 10 PRO. It can be downloaded from here https://docs.docker.com/docker-for-windows/install/

docker for win

After installation just press "Switch to Windows containers…"

Running your first container

If you've done an ASP.NET, you know that it is all hosted in IIS. Let's start with hosting plain IIS with docker.

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

Even as it called nanoserver, it is not that small as docker Alpine image. Base windows image is about 400mb and it takes about 2 minutes to download.

After it started going to your browser and open localhost:80. IIS starting page is there :)

If your browser could not resolve localhost, it means that you are using old "Docker for windows". To fix the issue you need to look for container IP address with the following command:

  
  docker inspect -f "{{ .NetworkSettings.Networks.nat.IPAddress }}" nano
  

And then open with following IP address:

iis

Next stage is to add volume to host some pictures with IIS. It is almost the same as in Linux. In Linux the root folder is "/", but in Windows it is "c:", to add volume just add -v <from>:<to> as here:

  
  docker run --name nano -d -it -p 80:80 -v c:\Work\Learn\win_docker:c:\inetpub\wwwroot\img  nanoserver/iis
  

Then in a browser open http://localhost/img/.jpg to see the picture.

ASP.NET/ASP.NET core

Running asp.net core as same as on windows server, except there is no IIS Management UI. So it is necessary to use Powershell. Before deploying to IIS . Asp.net application should be published. It can be done from another container or just publish via visual studio.

  
FROM microsoft/iis:latest
SHELL ["powershell"]

RUN Install-WindowsFeature NET-Framework-45-ASPNET ; \  
    Install-WindowsFeature Web-Asp-Net45

COPY ./publish /HelloWorldApi

RUN Remove-WebSite -Name 'Default Web Site'  
RUN New-Website -Name 'helloworld' -Port 80 \  
    -PhysicalPath 'C:\HelloWorldApi' -ApplicationPool '.NET v4.5'
&nbsp

It is pretty simple. Unfortunately, full ASP.NET framework can't be run with nano server. So it is required to download full windows image which is about 2GB. Then the page will open in the browser without a problem.

Asp.net core can be run the same way both with full iis image or nano server.

Enter container

Docker exec works the same as expecting. Of course, instead of shell, it is required to use CMD or PS commands.

Reason to use it

When I developed asp.net apps, I always struggle with configuring IIS. With docker, you can setup the startup script once and then use it from development to production. Do you need docker for windows? Decide yourself:) Maybe it is just easier to migrate to .net core or use PS to setup IIS.

Conclusion

  • All basic stuff work the same as on Linux.
  • Consider that root folder is "c:"
  • ASP.NET doesn’t work on windows nano server
  • Window server base images are huge

Comments (0)

Leave a Comment