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)
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.