If you’ve got Docker installed you can run a .NET Core sample quickly just like this. Try it:
docker run --rm microsoft/dotnet-samples
If your Docker for Windows is in “Windows Container mode” you can try .NET Framework (the full 4.x Windows Framework) like this:
docker run --rm microsoft/dotnet-framework-samples
Container images are easy to share via Docker Hub, the Docker Store, and private Docker registries, such as the Azure Container Registry. Also check out Visual Studio Tools for Docker. It all works very nicely together.
I like this quote from Richard Lander:
Imagine five or so years ago someone telling you in a job interview that they care so much about consistency that they always ship the operating system with their app. You probably wouldn’t have hired them. Yet, that’s exactly the model Docker uses!
And it’s a good model! It gives you guaranteed consistency. “Containers include the application and all of its dependencies. The application executes the same code, regardless of computer, environment or cloud.” It’s also a good way to make sure your underlying .NET is up to date with security fixes:
Docker is a game changer for acquiring and using .NET updates. Think back to just a few years ago. You would download the latest .NET Framework as an MSI installer package on Windows and not need to download it again until we shipped the next version. Fast forward to today. We push updated container images to Docker Hub multiple times a month.
The .NET images get built using the official Docker images which is nice.
.NET images are built using official images. We build on top of Alpine, Debian, and Ubuntu official images for x64 and ARM. By using official images, we leave the cost and complexity of regularly updating operating system base images and packages like OpenSSL, for example, to the developers that are closest to those technologies. Instead, our build system is configured to automatically build, test and push .NET images whenever the official images that we use are updated. Using that approach, we’re able to offer .NET Core on multiple Linux distros at low cost and release updates to you within hours.
Here’s where you can find .NET Docker Hub repos:
.NET Core repos:
.NET Framework repos:
- microsoft/dotnet-framework – includes .NET Framework runtime and sdk images.
- microsoft/aspnet – includes ASP.NET runtime images, for ASP.NET Web Forms and MVC, configured for IIS.
- microsoft/wcf – includes WCF runtime images configured for IIS.
- microsoft/iis – includes IIS on top of the Windows Server Core base image. Works for but not optimized for .NET Framework applications. The microsoft/aspnet and microsoft/wcfrepos are recommended instead for running the respective application types.
There’s a few kinds of images in the microsoft/dotnet repo:
- sdk — .NET Core SDK images, which include the .NET Core CLI, the .NET Core runtime and ASP.NET Core.
- aspnetcore-runtime — ASP.NET Core images, which include the .NET Core runtime and ASP.NET Core.
- runtime — .NET Core runtime images, which include the .NET Core runtime.
- runtime-deps — .NET Core runtime dependency images, which include only the dependencies of .NET Core and not .NET Core itself. This image is intended for self-contained applications and is only offered for Linux. For Windows, you can use the operating system base image directly for self-contained applications, since all .NET Core dependencies are satisfied by it.
For example, I’ll use an SDK image to build my app, but I’ll use aspnetcore-runtime to ship it. No need to ship the SDK with a running app. I want to keep my image sizes as small as possible!
For me, I even made a little PowerShell script (runs on Windows or Linux) that builds and tests my Podcast site (the image tagged podcast:test) within docker. Note the volume mapping? It stores the Test Results outside the container so I can look at them later if I need to.
docker build --pull --target testrunner -t podcast:test .
docker run --rm -v c:githubhanselminutes-coreTestResults:/app/hanselminutes.core.tests/TestResults podcast:test
Results File: /app/hanselminutes.core.tests/TestResults/_898a406a7ad1_2018-06-28_22_05_04.trx
Total tests: 22. Passed: 22. Failed: 0. Skipped: 0.
Test execution time: 8.9496 Seconds
Go read up on how the .NET Core images are built, managed, and maintained. It made it easy for me to get my podcast site – once dockerized – running on .NET Core on a Raspberry Pi (ARM32).
New Sponsor! Never type an invoice again! With DocSight OCR by ActivePDF, you’ll extract data from bills, invoices, PO’s & other documents using zonal data capture technology. Achieve Digital Transformation today!