Scott Hanselman

.NET and Docker

June 06, 2017 Comment on this post [17] Posted in Docker | DotNetCore
Sponsored By

“Container Ship” by NOAA's National Ocean Service is licensed under CC BY 2.0.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:\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.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service
June 06, 2017 4:44
I love the idea of using docker containers for builds. Do you know if there are plans for a build image for the full framework similar to the build image for core?
June 06, 2017 6:12
Hi Scott, this is awesome. But I still don't understand how to best manage the environment for deploying to docker from visual studio, i.e. for development, staging and production. Would be nice if you can share this as well.
June 06, 2017 16:25
Scott, I run a Synology NAS with Docker (DS415+) and have been trying to figure out what versions of .Net I can get running on it, especially as there's an MVC website I'd like to run off the NAS. On this page alone, you mention 5 different versions. Is there a specific recommendation in that regard?
June 06, 2017 17:37
Requiring Hypger V prevents running any third party VM, though... That's a tough loss... Perhaps I'll run it in a VM.
June 06, 2017 18:55
Any pointers on how you might dockerize an older MVC app that uses windows authentication?
June 06, 2017 19:06
Mike Schall,

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.
June 06, 2017 19:52
@Charles: Docker had a version that worked without Hyper-V (I think it used Virtual Box). I don't understand though why this is a limitation. For me it's important that I can use Linux images OR Windows images from docker-hub or an own repo if I prefer. So I've got more choices and not less.

Hyper-V is used to implement the containers and has nothing to do with using existing vm images (if this is what you meant)
June 06, 2017 21:31
Yeah.. Windows 10 and Hyper-V is a no go. It's amazing how Microsoft chooses to mock its users by forcing them to upgrade.
I was very hopeful that I would be able to run Docker for Windows, until they announced it will not run on Windows 7.
June 06, 2017 22:54
@Daniel, you're looking for Docker Toolbox https://www.docker.com/products/docker-toolbox

@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.
June 06, 2017 23:54
@Richard - Check out: https://github.com/Microsoft/Virtualization-Documentation/pull/592
Microsoft docs for Windows auth from within Windows container
June 07, 2017 0:14
@Bill Sears: that's the runtime image, not build image. At the Build conference they said that they're working on the build image for the full framework, but currently there is none.
June 07, 2017 1:14
Hi Scott,

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 :)
June 07, 2017 2:10
Hi Scott,

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?
June 07, 2017 2:21
@Jukka, @Bill Sears, @silentsod - Jukka has the right idea. I'm looking for a build environment image, not a runtime image. Nice to hear they are working on one. Hopefully something will be released soon.

Thanks for your responses.
June 07, 2017 18:13
Is there any community guidance on management UI's for Windows Server 2016 Docker Hosts?

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.
June 14, 2017 21:37
It's a shame about the Hyper-v requirement. I've had to disable hyper-v because I use the google android emulators which expect to use Intel HAXM. That doesn't seem to be able to sit alongside Hyper-V.

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.
June 20, 2017 1:39
Thanks for the great write-up Scott!
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.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.