.Net Core on (Linux vs Windows) Containers
Overview
We have been building microservices in .Net Core for quite some time and we have been able to Dockerize .Net Core Applications . For .Net Core, Docker can run the apps on linux or windows containers, depending upon which mode you have set in Docker for Windows(if you are using Windows 10 or Windows Server 2012) or what is the base image you are using while building Docker image for your application(if you are using Windows 7 or 8). We will find the similarities and dissimilarities between linux & windows containers and which one is better to host your .Net core app into.
Similarities
- Both work on containerization technique and doesn't require hypervisor or VM
- Both can be administered on Docker
- Provides same features
- Same commands to run
Dissimilarities
- Docker daemon process always need Linux to run. So when you install docker on linux, it only installs Docker engine and management tools and everything will work fine. But when we install docker on windows, its also install a Virtual Box in which the docker daemon process runs. In case of windows, there is lot of background process happening to set up the network access on Virtual box and to connect the Docker application with the VB.
- Docker can run on any linux based operating system e.g, debian, ubuntu etc. but it natively supports only Windows server 2012 and Windows 10
- Most Docker Orchestration systems such as Kubernetes does not support most Windows server versions while all of them support linux completely, exception is WS 2016 which is supported in Kubernetes. Docker Swarm support windows and linux both nicely.
Which is better?
There is no functional difference between Docker on linux or windows environments. Launching a Windows container vs. a Linux container is pretty much the same CLI with the exception of specifying a different container image. Having said that, most of the Docker orchestration systems supports almost all the linux based OS.Installation is bit faster in linux based OS.
Note: Docker swarm enables us to manage the server nodes in a cluster. Each node may contain multiple containers running the same or different images. Swarm manages the cluster and load balances the nodes on its own and it supports both Linux & windows platform. (We run .Net, Java etc. microservices in large number of containers on multiple nodes in one cluster using Swarm and it load balances them beautifully)
Considering above facts, it's bit easier to work with Docker on linux than on Docker on Windows.
Example
We have built a microservice in .Net Core 2.2.1 and hosted it on linux container. Since, my local system has Windows 7, i had to install Docker toolbox which has Docker engine, tools and Virtual Box.
- Start the Docker Quick Start Terminal
- Below is the Dockerfile of our .Net Core app which uses 2.1-sdk from microsoft/dotnet repository
- Let's go to Docker hub and fetch the Docker file of 2.1-sdk image, which looks like below
- As we see, it uses stretch-scm image from buildpack-deps repository. We can backtrack the base images to a level where we find the base image of OS it is using. In above case, backtracking leads us to stretch-curl image from buildpack-deps repository which is using debian linux based OS.
- Lets run our app in the docker container and confirm which container it is running on
- Once my app is running, i fetch the container Id
- Then using container Id, i will get into the working directory of the container and try to print the name of the OS being used inside container
- As we see, it prints Linux. The .Net core service is running on Linux container.
I hope this blog will help to have better understanding of Linux vs Windows containers on Docker. I am also on learning path and would like to know if i can improve or correct anything on this blog.
Thanks for going through.
if(needAnyHelp)
ClickMe(Nikhil Jain);
else
{
var func = () => Console.WriteLine("See You Later");
func();
}