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
1.0.5,1.0,lts1.1.2,1.1,1,latest2.0.0-preview2,2.0,22.0.0-preview2-jessie,2.0-jessie,2-jessie(Dockerfile)1.0-1.1-2017-05,1.0-1.1(designed for CI builds)1.0-2.0-preview2-2017-06,1.0-2.0-preview2(designed for CI builds)1.0-2.0-preview2-2017-06-jessie,1.0-2-0-preview2-jessie(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.
- 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
- 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.
Example Usage
Build an app with docker build
With this technique your application is compiled in two stages when you run docker build. Docker 17.05 or newer is required.
Stage 1 compiles and publishes the application by using the microsoft/aspnetcore-build image. Stage 2 copies the published application
from Stage 1 into the final image leaving behind all of the source code and tooling needed to build.
Create a
.dockerignorefile in your project folder and exclude files that shouldn't be copied into the container:# Sample contents of .dockerignore file bin/ obj/ node_modules/Create a
Dockerfilein your project:# Sample contents of Dockerfile # Stage 1 FROM microsoft/aspnetcore-build AS builder WORKDIR /source # caches restore result by copying csproj file separately COPY *.csproj . RUN dotnet restore # copies the rest of your code COPY . . RUN dotnet publish --output /app/ --configuration Release # Stage 2 FROM microsoft/aspnetcore WORKDIR /app COPY --from=builder /app . ENTRYPOINT ["dotnet", "myapp.dll"]This approach has the advantage of caching the results of
dotnet restoreso that packages are not downloaded unless you change your
project file.Build your image:
$ docker build -t myapp .(Linux containers) Start a container from your image. This will expose port 5000 so you can browse it locally at http://locahost:5000.
$ docker run -it -p 5000:80 myapp(Windows containers) Start a container from your image, get its assigned IP address, and then open your browser to the IP address
of the container on port 80. To see console output, attach to the running container or usedocker logs.PS> docker run --detach --name myapp_container myapp PS> docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' myapp_container PS> docker attach myapp_container
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 is completed, the application in the current directory will be published to the bin/Release/PublishOutput directory.
Sorry, typo in link i posted, here is correct one: https://www.linkedin.com/pulse/net-core-v111-docker-container-linux-tutorial-joe-hoeller--1
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.
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.
This is useful when publish an asp.net core app!
@martinibanez This issue identified and opened here https://github.com/dotnet/dotnet-docker/issues/175
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.