Cross Platform And Container Support Feature - ASP.NET Core

As we all know, ASP.NET Core is now becoming the most popular web application development tool for developing web applications on .NET platform in a  smart way.
Being  open-source, ASP.NET Core has another great feature called cross-platform and container support, this means it can run on Windows, Linux and macOS, which makes this platform more unique and robust.
Cross Platform And Container Support Feature - ASP.NET Core
ASP.NET Core was initially released in 2016 which was Windows OS only and later on it was re-designed to have cross-platform support.


  • It can run on Windows, macOS and different/multiple distributions of Linux.
  • Another feature is it can support different CPU architecture.
  • We can now develop and publish application on Windows, macOS and Linux too.

Container Support

Another feature of ASP.NET Core is Container support so that you can place your published code directly in a container.
There are many containers available in the market like Docker, LXC, rkt, Kubernetes, Cloud Foundry and Vagrant.
Let’s understand Container in a simple way.
Container is nothing but a lightweight, standalone and executable package set of software that is required by application to run. In other words, Container is a software which includes an application and all of its runtime dependencies. 
  • Runtime
  • Code
  • System Tools
  • System Library
  • Other Settings required by application  
So, in simple words,  Container helps us to build an application once and run it anywhere. Also we can isolate each application on a host operating system.
Before we understand how it works with ASP.NET Core, we need to install Docker first if are working on Windows Platform.
Use this link to install Docker for Windows. 
Once installation is done, now let's understand in brief how Doker Container works with ASP.NET Core.
  1. Develop and publish a required ASP.NET Core application
  2. Once published, then create and configure a Dockerfile for ASP.NET Core application
  3. Once the above step is done build a Docker image
  4. Once build is done then create and run a Docker container at the end
Cross Platform And Container Support Feature - ASP.NET Core
Once we are done with this, we will see a new Dockerfile is created at the same root of where our project files exist as below. 
Cross Platform And Container Support Feature - ASP.NET Core
So now this Docker file will run your created application inside container.
Let's have a look at how it looks.
  1. #Depending on the operating system of the host machines(s) that will build or run the containers, the image specified in the FROM statement may need to be changed.  
  2. #For more information, please see  
  4. FROM AS base  
  5. WORKDIR /app  
  6. EXPOSE 80  
  7. EXPOSE 443  
  9. FROM AS build  
  10. WORKDIR /src  
  11. COPY ["TestDocker.csproj"""]  
  12. RUN dotnet restore "./TestDocker.csproj"  
  13. COPY . .  
  14. WORKDIR "/src/."  
  15. RUN dotnet build "TestDocker.csproj" -c Release -o /app/build  
  17. FROM build AS publish  
  18. RUN dotnet publish "TestDocker.csproj" -c Release -o /app/publish  
  20. FROM base AS final  
  21. WORKDIR /app  
  22. COPY --from=publish /app/publish .  
  23. ENTRYPOINT ["dotnet""TestDocker.dll"]  
You will see the Docker option as in the below screen to run your application under Docker Container.
Cross Platform And Container Support Feature - ASP.NET Core
Above is a sample Docker file which defines a set of instructions or rules that creates an image for the specific application.   
Benifits of using Docker with ASP.NET Core.
  • One of the main benefit of using ASP.Net Core for Docker is it allows to run .Net versions of applications side by side within the same machine on which it is hosted.
  • .NET Core application can easily run in a Docker container with minimum efforts, thanks to Microsoft. 
  • Containers provide a smooth lightweight way to isolate your application from the rest of the host system and which sharing only just the kernel and using resources given to your application on which it is depend.
In short a container is a runnable instance of an image, as you build your image, you deploy your application and dependencies. And then, multiple containers can be instantiated and each one is isolated from one another. Each and every container instance has its own memory, network interface and filesystem. 
I hope you like this article and it's helpful.