This repo contains samples that demonstrate various .NET Core Docker configurations, which you can use as the basis of your own Docker images. They are also generally useful .NET Core samples and provide instructions for use with and without Docker.
These samples depend on the .NET Core Docker images on Docker Hub, provided by the .NET Team at Microsoft.
Docker uses docker/whalesay as a getting started sample. The .NET Core Team at Microsoft uses dotnetbot, which is the mascot for .NET open source projects. Got something to say? Both whalesay and dotnetbot are great listeners. The dotnetapp-dev, dotnetapp-prod, and dotnetapp-selfcontained samples all simply print a "Welcome!" message to the console. The aspnetapp sample starts a basic ASP.NET Core website running in a container that you can browse to locally.
You can pick the sample that best fits the scenario you are interested in. The instructions for each sample describe how to target Windows or Linux Docker images, from Windows, Linux or macOS.
The samples use .NET Core 2.0. They use Docker multi-stage build and multi-arch tags where appropriate.
You need to have the .NET Core SDK and Git and Docker client 17.06 or newer clients installed to use these samples.
You can run a sample application that runs from a pre-built image that has been published to Docker Hub. The source of this sample application is the dotnetapp-prod sample.
To run the Linux image:
docker run microsoft/dotnet-samples
To run the Windows image:
docker run microsoft/dotnet-samples:dotnetapp-nanoserver
It is recomended to run the sample twice. The second run will not include downloading the image, so is more representative of typical Docker use.
The following samples show different ways to use .NET Core images.
- .NET Core Development Sample - 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).
- .NET Core Docker Production Sample - 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.
- .NET Core self-contained application Docker Production Sample - 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.
- ASP.NET Core Docker Production Sample - This samples demonstrates a Dockerized ASP.NET Core Web App.
- .NET Core Docker Production Sample - This sample includes instructions for running a runtime image with Linux on a Raspberry Pi.
- .NET Core self-contained application Docker Production Sample - This sample includes instructions for running a self-contained image with Linux on a Raspberry Pi.
- Related: See .NET Core on Raspberry Pi
-
.NET Core Docker Alpine Production Sample - This sample illustrates how to use the new lightweight Alpine based .NET Core Runtime image that is currently in preview.
-
Related: See .NET Core Alpine Docker Image announcement
See the following related Docker Hub repos:
- microsoft/dotnet for .NET Core images.
- microsoft/dotnet-samples for .NET Core sample images.
- microsoft/aspnetcore for ASP.NET Core images.
- microsoft/aspnet for ASP.NET Web Forms and MVC images.
- microsoft/dotnet-framework for .NET Framework images (for web applications, see microsoft/aspnet).
See the following related GitHub repos:
- dotnet/announcements for Docker-related announcements.
- microsoft/dotnet-framework-docker-samples for .NET Framework samples.