Public | Automated Build

Last pushed: 4 days ago
Short Description
Official images for building ASP.NET Core applications.
Full Description

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.


Supported tags

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.
  • Node.js
  • Bower
  • Gulp

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.

Related images

  1. microsoft/dotnet - the .NET Core image if you don't need the ASP.NET Core specific optimizations.
  2. microsoft/aspnetcore - the ASP.NET Core runtime image, for when you don't need to build inside a container.

Example Usage

Build an app with docker run

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 bin/Release/PublishOutput directory.

Build an app with docker build

With this technique your application is compiled when you run docker build and you then copy the binaries out of the built image.

  1. Create a Dockerfile to build your application (Dockerfile.build is a common name used).

     FROM microsoft/aspnetcore-build
     WORKDIR /app
    
     COPY *.csproj .
     RUN dotnet restore
    
     COPY . .
     RUN dotnet publish --output /out/ --configuration Release
    
  2. Build your image:

     $ docker build -t build-image -f Dockerfile.build
    
  3. 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 bin/Release/PublishOutput directory.

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.

Docker Pull Command
Owner
microsoft
Source Repository

Comments (5)
molnarad
5 days ago

Wouldn't it make sense to include nuget? Can't do much without that installed as well.

natemcmaster
2 months ago

Tip: as Docker Hub does not send notifications when comments are made here, you will get a faster response to questions and issues by posting to https://github.com/aspnet/aspnet-docker.

xin3222634
3 months ago

This is useful when publish an asp.net core app!

natemcmaster
3 months ago

@martinibanez This issue identified and opened here https://github.com/dotnet/dotnet-docker/issues/175

martinibanez
3 months ago

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".
"dotnet restore"

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.