.NET and Docker
.NET and .NET Core (and Windows!) have been getting better and better with Docker. I run Docker for Windows as it supports both Linux Containers and Windows Containers. They have both a Stable and Edge channel. The Edge (Beta) channel is regularly updated and, as a rule, gets better and better in the year I've been running it.
As a slightly unrelated side note, I'm also running Docker on my Synology NAS with a number of containers, as well as .NET Core (my Nas is an Intel chip), Minecraft Server, Plex Server, and CrashPlan.
NOTE: Docker for Windows requires 64bit Windows 10 Pro and Microsoft Hyper-V. Please see What to know before you install for a full list of prerequisites.
The .NET Team at Microsoft has been getting their dockerfiles in order and organized. It can seem initially the opposite, with lots of cryptic tags and names, but there's a clear method you can read about here.
They publish their Docker images in a few different repositories on Docker Hub. It’s important to segment images so that they are easier to find, both on the Docker Hub website as well as with the docker search
command.
- microsoft/dotnet — .NET Core Runtime and SDK images for Linux and Nano Server.
- microsoft/aspnetcore — ASP.NET Core images for Linux and Nano Server.
- microsoft/aspnetcore-build — ASP.NET Core images for Linux and Nano Server, intended for building apps.
- microsoft/dotnet-framework — .NET Framework 3.5 and 4.6.2 images for Windows Server Core.
- microsoft/aspnet — .NET Framework 3.5 and 4.6.2 ASP.NET images for Windows Server Core.
There's also some samples at:
- microsoft/dotnet-samples — .NET Core samples.
- microsoft/dotnet-framework-samples — .NET Framework samples.
The samples are super easy to try out - STOP READING AND TRY THIS NOW. ;)
I'm always impressed with a nice asynchronous ASCII Progress bar. I'm easy to impress. This is a "hello world" sample with a surprise ASCII art. I won't spoil for you.
C:\Users\scott\Desktop> docker run microsoft/dotnet-samples
Unable to find image 'microsoft/dotnet-samples:latest' locally
latest: Pulling from microsoft/dotnet-samples
10a267c67f42: Downloading [========> ] 9.19MB/52.58MB
7e1a7ec87c21: Downloading [======================> ] 10.8MB/18.59MB
923d0cd2ed37: Download complete
7c523004cf83: Downloading [=========> ] 6.144MB/33.07MB
f3582118a43a: Waiting
c27ef6b597a0: Waiting
All the images are managed and maintained on GitHub so you can get involved if you're not digging the images or files.
One interesting thing to point out is the difference between dev images and production images, as well as images you'd use in CI/CD (Build Server) situations to build other images. Here are some examples from GitHub:
Development
- dotnetapp-dev - This sample is good for development and building since it relies on the .NET Core SDK image. It performs
dotnet
commands on your behalf, reducing the time it takes to create Docker images (assuming you make changes and then test them in a container, iteratively).
Production
- dotnetapp-prod - This sample is good for production since it relies on the .NET Core Runtime image, not the larger .NET Core SDK image. Most apps only need the runtime, reducing the size of your application image.
- dotnetapp-selfcontained - This sample is also good for production scenarios since it relies on an operating system image (without .NET Core). Self-contained .NET Core apps include .NET Core as part of the app and not as a centrally installed component in a base image.
- dotnetapp-current - This sample demonstrates how to configure an application to use the .NET Core 1.1 image. Both the .csproj and the Dockerfile have been updated to depend on .NET Core 1.1. This sample is the same as dotnetapp-prod with the exception of relying on a later .NET Core version.
- aspnetapp - This samples demonstrates a Dockerized ASP.NET Core Web App
There's great Docker support in VS Code, Visual Studio 2017, and Visual Studio for Mac (the Preview channel). With VS and Docker on Windows you can even F5 (debug) into a Linux Container.
Some of you may have .NET Framework apps running in Virtual Machines that you'd love to get moved over to a container infrastructure. There's a tool called Image2Docker that Docker maintains that might help. It helps migrate VMs to Containers. Check out the Image2Docker DockerCon talk or read Docker’s Convert ASP.NET Web Servers To Docker with ImageDocker to learn more.
“Container Ship” by NOAA's National Ocean Service is licensed under CC BY 2.0
Sponsor: Check out Seq: simple centralized logging, on your infrastructure, with great support for ASP.NET Core and Serilog. Download version 4.0.
About Scott
Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.
About Newsletter
Is this what you're looking for? It runs on Windows 10 Core but I believe it is a full version of the .NET Framework (either 4.6.2 or 3.5). Check it out.
Hyper-V is used to implement the containers and has nothing to do with using existing vm images (if this is what you meant)
I was very hopeful that I would be able to run Docker for Windows, until they announced it will not run on Windows 7.
@Mike VS2017 is looking to have support for right clicking and Create Docker image for your full .NET Framework applications. This was demoed at DevIntersection this year.
Microsoft docs for Windows auth from within Windows container
Just watched a great video on channel9 where they debug mult-container applications straight from VS2017, is this possible using VS Code? Preferably utilising the same mechanisms as VS2017, rather than yo docker for example.
Thanks,
Max
PS: Keep up the good work, absolutely love your blog :)
I run a Synology 1513+ and am very happy with it. Am experimenting with .Net on Docker for Mac with a view to moving it the NAS once Core 2.0 is stable. Do you have extra RAM installed on your 1511?
Thanks for your responses.
I know about (and have used) Rancher Labs, but I also see that Docker will be making their UCP (Universal Control Plane) available to Windows Server hopefully at some point. These all have similar features: DNS, Load Balancing, Service Discovery, and some sort of container scheduler.
Having said that, I could presumably make use of one of your previous awesome blog posts to get around this to some degree. The hanselman.com encyclopedia.
http://jumperads.com/transfer-furniture-jeddah.html
http://jumperads.com/transfer-furniture-dammam.html
http://jumperads.com/transfer-furniture-medina-almonawara.html
http://jumperads.com/transfer-furniture-taif.html
Comments are closed.