I am currently dockerizing a aspnetcore microservice application which has 3 services. I would like to create a dockerfile for each service and use docker-compose to run it, which already succussful implemented. However, each time I have
publish the dotnet app into a folder first and then
build the image separately and I like to inculde the build in the dockerfile.
I found this question which is very similar to my question asp.net core 2.0 – multiple projects solution docker file but the difference is for each service, I have reference to the
core.library(which share some common files that use across different service).
The project structure is like this:
- /root(contain .sln)
Below is the dockerfile in auth.service
FROM microsoft/aspnetcore:2.0 AS base WORKDIR /app EXPOSE 80 FROM microsoft/aspnetcore-build:2.0 AS build WORKDIR /src COPY ["auth.service.csproj", "dotnetapp/"] COPY ["Common.library.csproj", "Common.library/"] RUN dotnet restore "auth.service.csproj" COPY . . WORKDIR "/src/auth.service" RUN dotnet build "auth.service.csproj" -c Release -o /app FROM build AS publish RUN dotnet publish "auth.service.csproj" -c Release -o /app FROM base AS final WORKDIR /app COPY --from=publish /app . ENTRYPOINT ["dotnet", "auth.service.dll"]
Everything is running well except the line
COPY ["Common.library.csproj", "Common.library/"]. It throws error like cannot find the file which is right. The
Common.library.csproj is not inside the
Then I tried to re-write this to
copy ../Common.library/Common.library.csproj but since we cannot copy the source outside of the current directory(docker said that), so it doesn’t work.
I tried to change the properties of project dependencies of common.library from to copy local -> true, but it doesn’t work.
Any help would be really appreciated!