ASP.NET 5: docker assembly with multi-project solution

I am trying to create an image of my 4-project ASP.NET 5 solution. Here is the structure:

  • FlashTools (ASP.NET 5 Class Library)
  • Models (ASP.NET 5 Class Library)
  • QuizzCorrector (ASP.NET 5 Web Application)
  • QuizzService (ASP.NET 5 Class Library)

I have a simple Docker file that looks like this:

FROM microsoft/aspnet COPY . /app WORKDIR /app RUN ["kpm", "restore"] EXPOSE 5004 ENTRYPOINT ["k", "kestrel"] 

But not sure where to put it. In the root folder of my solution, where is global.json, or in the folder of my web application, where is my project.json? Of course, I changed it depending on where this file is located.

In any case, both work because they load all the libraries I need when I run the command

docker build -t quizzcorrector.

My problem is the moment the docker tells me

Could not find Models> = 1.0.0

Could not find FlashTools> = 1.0.0

Could not find QuizzService> = 1.0.0

I saw in this thread https://github.com/aspnet/aspnet-docker/issues/19 that in a multi-project solution, we have to run the "kpm pack" command to pack my application in a deployable and manageable form.

I could not find any Dockerfiles examples with the kpm pack command, only the documentation: https://github.com/aspnet/Home/wiki/Package-Manager

I also, of course, tried to use the ADD or COPY commands in my Docker file to copy the contents of my projects to the container file system, but still the same error.

Thank you for helping me.

+7
docker asp.net-core
source share
4 answers

Updated: February 14, 2018

My previous answer does not take into account recommendations for writing a Docker file. It also does not work for those solutions that have several web projects, where each application should work in a separate Docker container. It would be best to create and publish an ASP.NET Core application in a development environment and run the application in a Docker container that is optimized for use in production.

  • Create Docker File in Web Application Folder
  • Put the following contents in it

     FROM microsoft/aspnetcore COPY ./publish /publish WORKDIR /publish EXPOSE 5000/tcp ENTRYPOINT ["dotnet", "QuizzCorrector.dll"] 
  • Create and publish the project by running dotnet publish -c Release -o publish
  • Create a docker build -t QuizzCorrector image by running docker build -t QuizzCorrector

Please note that microsoft/aspnetcore Docker image is just a runtime image that does not provide the .NET Core SDK, which makes it easier and better to use in production.


It may be late, but I'm going to answer this question for those who are still trying to get it to work. You need to create a Dockerfile at the solution level. Then you need to update the working folder to use the one where the web project is located. The following is the final Dockerfile, given that the kpm and k utilities kpm been replaced by a single dotnet tool.

 FROM microsoft/dotnet:latest COPY . /app WORKDIR /app/src/QuizzCorrector RUN ["dotnet", "restore"] EXPOSE 5004 ENTRYPOINT ["dotnet", "run"] 

+17
source share

Perhaps it is not too late for this answer.

In this post http://dev.widemeadows.de/2015/09/08/fun-with-asp-net-5-beta7-bliss-build-errors-dockerfiles-and-reverse-proxies/ you should make a file, which, by decision, refers to the entire project, referring to the initial project.

0
source share

To be able to create and run multiple x projects in DockerHub using ASP.NET CORE 1.0, I had a similar problem. It brought me here and helped me. My solution was as follows:

Solution structure

 ``` Root β”‚ AuthenticationService.sln β”‚ Dockerfile β”‚ └───src β”‚ β”‚ β”‚ └───AuthenticationService β”‚ └───DataAccess β”‚ └───EntityDataModels β”‚ └───Services . 

Dockerfile:

 FROM microsoft/dotnet:latest COPY . /app WORKDIR /app/src/AuthenticationService RUN ["dotnet", "restore"] WORKDIR /app/src/DataAccess RUN ["dotnet", "restore"] WORKDIR /app/src/EntityDataModels RUN ["dotnet", "restore"] WORKDIR /app/src/Services RUN ["dotnet", "restore"] WORKDIR /app/src/AuthenticationService RUN ["dotnet", "build"] EXPOSE 5000/tcp ENV ASPNETCORE_URLS http://*:5000 ENTRYPOINT ["dotnet", "run"] 
0
source share

For Future Reference and those who have the same problem. Microsoft released the Sample dotnet core app with the dotnet-architecture / eShopOnContainers Project dock containers here

You can refer to the link or find an example below

Example:

 FROM microsoft/aspnetcore:2.0 AS base WORKDIR /app EXPOSE 80 FROM microsoft/aspnetcore-build:2.0 AS build WORKDIR /src COPY eShopOnContainers-ServicesAndWebApps.sln ./ COPY src/Services/Basket/Basket.API/Basket.API.csproj src/Services/Basket/Basket.API/ COPY src/BuildingBlocks/HealthChecks/src/Microsoft.AspNetCore.HealthChecks/Microsoft.AspNetCore.HealthChecks.csproj src/BuildingBlocks/HealthChecks/src/Microsoft.AspNetCore.HealthChecks/ COPY src/BuildingBlocks/HealthChecks/src/Microsoft.Extensions.HealthChecks/Microsoft.Extensions.HealthChecks.csproj src/BuildingBlocks/HealthChecks/src/Microsoft.Extensions.HealthChecks/ COPY src/BuildingBlocks/EventBus/EventBusRabbitMQ/EventBusRabbitMQ.csproj src/BuildingBlocks/EventBus/EventBusRabbitMQ/ COPY src/BuildingBlocks/EventBus/EventBus/EventBus.csproj src/BuildingBlocks/EventBus/EventBus/ COPY src/BuildingBlocks/EventBus/EventBusServiceBus/EventBusServiceBus.csproj src/BuildingBlocks/EventBus/EventBusServiceBus/ RUN dotnet restore COPY . . WORKDIR /src/src/Services/Basket/Basket.API RUN dotnet build -c Release -o /app FROM build AS publish RUN dotnet publish -c Release -o /app FROM base AS final WORKDIR /app COPY --from=publish /app . ENTRYPOINT ["dotnet", "Basket.API.dll"] 
0
source share

All Articles