Skip to content
Branch: master
Find file History
Michael Simons (VISUAL STUDIO) Michael Simons (VISUAL STUDIO)
Michael Simons (VISUAL STUDIO) and Michael Simons (VISUAL STUDIO) Merged PR 771: [master] Add support for Window Server, version 1903
Related to #1019
Latest commit d39eb71 May 21, 2019
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
dotnetapp
tests
utils
.dockerignore
Directory.Build.props
Dockerfile
Dockerfile.alpine-x64
Dockerfile.alpine-x64-globalization
Dockerfile.alpine-x64-selfcontained
Dockerfile.debian-arm32-selfcontained
Dockerfile.debian-x64-selfcontained
Dockerfile.nanoserver-x64-selfcontained
README.md
build.cmd
build.ps1
build.sh
dotnet-docker-arm32.md
dotnet-docker-arm64.md
dotnet-docker-dev-in-container.md
dotnet-docker-selfcontained.md
dotnet-docker-unit-testing.md
dotnetapp.sln
push-image-to-acr.md
push-image-to-dockerhub.md

README.md

.NET Core Docker Sample

This sample demonstrates how to use .NET Core and Docker together. It builds multiple projects and executes unit tests in a container. The sample works with both Linux and Windows containers and can also be used without Docker.

The sample builds the application in a container based on the larger .NET Core SDK Docker image. It builds and tests the application and then copies the final build result into a Docker image based on the smaller .NET Core Docker Runtime image. It uses Docker multi-stage build and multi-arch tags.

This sample requires Docker 17.06 or later of the Docker client.

Try a pre-built .NET Core Docker Image

You can quickly run a container with a pre-built .NET Core Docker image, based on this sample.

Type the following Docker command:

docker run --rm mcr.microsoft.com/dotnet/core/samples

Getting the sample

The easiest way to get the sample is by cloning the samples repository with git, using the following instructions.

git clone https://github.com/dotnet/dotnet-docker/

You can also download the repository as a zip.

Build and run the sample with Docker

You can build and run the sample in Docker using the following commands. The instructions assume that you are in the root of the repository.

cd samples
cd dotnetapp
docker build --pull -t dotnetapp .
docker run --rm dotnetapp Hello .NET Core from Docker

The commands above run unit tests as part docker build. You can also run .NET unit tests as part of docker run. The following instructions provide you with the simplest way of doing that.

docker build --target testrunner -t dotnetapp:test .
docker run --rm -it dotnetapp:test

You can mount a volume while running the image in order to save the test results to your local disk. The instructions to do that are provided in Running Unit Tests with Docker

Multiple variations of this sample have been provided, as follows. Some of these example Dockerfiles are demonstrated later. Specify an alternate Dockerfile via the -f argument.

Build and run the sample for Alpine with Docker

You can build and run the sample with Alpine using the following commands. The instructions assume that you are in the root of the repository.

cd samples
cd dotnetapp
docker build --pull -t dotnetapp:alpine -f Dockerfile.alpine-x64 .
docker run --rm -it dotnetapp:alpine Hello .NET Core from Alpine

Globalization is disabled by default with Alpine images in order to produce smaller images. You can re-enable globalization if your application relies on it. Dockerfile.alpine-x64-globalization enables globalization for Alpine images, but produces larger images.

Build and run the sample for Ubuntu 18.04 with Docker

You can also build for Ubuntu 18.04, with a bionic tag. The bionic tags are documented at dotnet/core/sdk and dotnet/core/runtime. You would switch to use the 2.2-bionic tag for both the build and runtime phases.

Build and run the sample for Linux ARM32 with Docker

You can build and run the sample for ARM32 and Raspberry Pi with Build .NET Core Applications for Raspberry Pi with Docker instructions.

Build and run the sample for Linux ARM64 with Docker

Build .NET Core Self-Contained Applications with Docker

You can build Build .NET Core Self-Contained Applications with Docker.

Develop .NET Core Applications in a container

You can develop applications without a .NET Core installation on your machine with the Develop .NET Core applications in a container instructions. These instructions are also useful if your development and production environments do not match.

Run Docker Image on Another Device

You can push the image to a container registry so that you can pull and run it on another device. Straightforward instructions are provided for pushing to both Azure Container Registry and DockerHub.

Build and run the sample locally

You can build and run the sample locally with the .NET Core 2.2 SDK using the following instructions. The instructions assume that you are in the root of the repository.

cd samples
cd dotnetapp
dotnet run Hello .NET Core

You can produce an application that is ready to deploy to production using the following command.

dotnet publish -c Release -o out

You can run the published application using the following command:

cd out
dotnet dotnetapp.dll

Note: The -c Release argument builds the application in release mode (the default is debug mode). See the dotnet publish reference for more information on commandline parameters.

.NET Resources

More Samples

Docs and More Information:

Related Docker Hub Repositories

.NET Core:

.NET Framework:

You can’t perform that action at this time.