ASP.NET Core Build Docker Image
This repository contains images that are used to compile/publish ASP.NET Core applications inside the container. This is different to compiling an ASP.NET Core application and then adding the compiled output to an image, which is what you would do when using the microsoft/aspnetcore image. These Dockerfiles use the microsoft/dotnet image as its base.
1.0-1.1(designed for CI builds), (Dockerfile)
1.0-1.1-2017-03-nanoserver(designed for CI builds), (Dockerfile)
What is ASP.NET Core?
ASP.NET Core is a new open-source and cross-platform framework for building modern cloud based internet connected applications, such as web apps, IoT apps and mobile backends. It consists of modular components with minimal overhead, so you retain flexibility while constructing your solutions. You can develop and run your ASP.NET Core apps cross-platform on Windows, Mac and Linux. ASP.NET Core is open source at GitHub.
This image contains:
- .NET Core SDK so that you can create, build and run your .NET Core applications.
- A NuGet package cache for the ASP.NET Core libraries. This will significantly improve the initial package restore performance when building ASP.NET Core application.
The CI Image (
1.0-1.1) contains both the 1.0 and 1.1 pre-restored packages. It is intended for when you have a solution containing both 1.1.x and 1.0.x projects and want to build them all in the same container, gaining advantage of the pre-restored packages. Because it has an extra set of packages it is bigger than the other, more focused, images.
- microsoft/dotnet - the .NET Core image if you don't need the ASP.NET Core specific optimizations.
- microsoft/aspnetcore - the ASP.NET Core runtime image, for when you don't need to build inside a container.
Build an app with
You can use this container to compile your application when it runs. If you use the Visual Studio tooling to setup CI/CD to Azure Container Service then this method of using the build container is used.
Run the build container, mounting your code and output directory, and publish your app:
docker run -it -v $(PWD):/app --workdir /app microsoft/aspnetcore-build bash -c "dotnet restore && dotnet publish -c Release -o ./bin/Release/PublishOutput"
After this has run the application in the current directory will be published to the
Build an app with
With this technique your application is compiled when you run
docker build and you then copy the binaries out of the built image.
Create a Dockerfile to build your application (
Dockerfile.buildis a common name used).
FROM microsoft/aspnetcore-build WORKDIR /app COPY *.csproj . RUN dotnet restore COPY . . RUN dotnet publish --output /out/ --configuration Release
Build your image:
$ docker build -t build-image -f Dockerfile.build
Create a container from your image and copy your built application out.
$ docker create --name build-cont build-image $ docker cp build-cont:/out ./bin/Release/PublishOutput
After this the application in the current directory will be published to the
From here you could construct an optimized runtime image with the
microsoft/aspnetcore image or just deploy/run the binaries as normal without using Docker at runtime.
This approach has the advantage of caching the results of
dotnet restore so that packages are not downloaded unless you change your project file.
In case anyone is having issues running .NET Core v1.1.1 inside a Docker Container, and then deploying to a Linux Server, I made this tut:
what about 1.1.0-projectjson version?
did you suspend projectjson support with 1.1.1?
Wouldn't it make sense to include nuget? Can't do much without that installed as well.
This is useful when publish an asp.net core app!
It seems that this image (2016-12-19) is not working with the newest version of the CLI and SDK. My local Version of the 1.1 SDK is 1.0.0-preview4-004233 and the version within this image is 1.0.0-preview3-004056.
This means that I cannot get my testproject to compile. It always throws this error "error MSB4057: The target Restore does not exist in the project."
Steps to replicate:
"dotnet new -t Web" //create new testproject
Edit *.csproj and change to netcoreapp1.1 and Microsoft.NETCore.App Version to "1.1.0".
Test with "dotnet run".
Start the docker container in interactive mode
docker run -it --rm -v "$pwd\:/sln" --workdir /sln microsoft/aspnetcore-build:1.1.0-msbuild
Within the container try "dotnet restore" and you will get the above error.
The production version of the image microsoft/aspnetcore is running fine with the published testproject.