.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.
There’s also some samples at:
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:UsersscottDesktop> 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
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:
- dotnetapp-dev – This sample is good for development and building since it relies on the .NET Core SDK image. It performs
dotnetcommands on your behalf, reducing the time it takes to create Docker images (assuming you make changes and then test them in a container, iteratively).
- 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
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.