1 year ago
#381266
Mr. E
Buiding a Docker image with a external project reference (outside solution)
I'm having trouble building a Docker Image of my project. In my project I have a project reference from an application, which is not in the same solution as my project. When I try to build my Docker image I get the following errors/warnings:
PS C:\Trunk\Tools\Dashboard> docker build -f Server/Dockerfile --force-rm -t dashboardserver .
[+] Building 228.2s (15/17)
=> [internal] load build definition from Dockerfile 0.1s
=> => transferring dockerfile: 579B 0.1s
=> [internal] load .dockerignore 0.1s
=> => transferring context: 35B 0.0s
=> [internal] load metadata for mcr.microsoft.com/dotnet/sdk:6.0 0.9s
=> [internal] load metadata for mcr.microsoft.com/dotnet/aspnet:6.0 0.0s
=> [base 1/2] FROM mcr.microsoft.com/dotnet/aspnet:6.0 0.0s
=> [build 1/7] FROM mcr.microsoft.com/dotnet/sdk:6.0@sha256:a2a8f968b043349b8faa0625c5405ac33da70b3274ff9e17109430f16aa9a3ee 0.0s
=> [internal] load build context 2.2s
=> => transferring context: 1.32MB 2.2s
=> CACHED [base 2/2] WORKDIR /app 0.0s
=> CACHED [final 1/2] WORKDIR /app 0.0s
=> CACHED [build 2/7] WORKDIR /src 0.0s
=> CACHED [build 3/7] COPY [Server/Server.csproj, Server/] 0.0s
=> [build 4/7] RUN dotnet restore "Server/Server.csproj" 94.6s
=> [build 5/7] COPY . . 0.2s
=> [build 6/7] WORKDIR /src/Server 0.2s
=> ERROR [build 7/7] RUN dotnet build "Server.csproj" -c Release -o /app/build 102.3s
------
> [build 7/7] RUN dotnet build "Server.csproj" -c Release -o /app/build:
#15 3.459 Microsoft (R) Build Engine version 17.1.0+ae57d105c for .NET
#15 3.459 Copyright (C) Microsoft Corporation. All rights reserved.
#15 3.459
#15 4.336 Determining projects to restore...
#15 4.341 Skipping project "/SomeApp/Api/SomeApp.Api.csproj" because it was not found.
#15 4.343 Skipping project "/SomeApp/Api/SomeApp.Api.csproj" because it was not found.
#15 4.729 All projects are up-to-date for restore.
#15 5.139 /usr/share/dotnet/sdk/6.0.201/Microsoft.Common.CurrentVersion.targets(2065,5): warning : The referenced project '../../../SomeApp/Api/SomeApp.Api.csproj' does not exist. [/src/Server/Server.csproj]
#15 97.00 /src/Server/Program.cs(9,7): error CS0246: The type or namespace name 'SomeApp' could not be found (are you missing a using directive or an assembly reference?) [/src/Server/Server.csproj]
#15 98.57
#15 98.57 Build FAILED.
#15 98.57
#15 98.57 /usr/share/dotnet/sdk/6.0.201/Microsoft.Common.CurrentVersion.targets(2065,5): warning : The referenced project '../../../SomeApp/Api/SomeApp.Api.csproj' does not exist. [/src/Server/Server.csproj]
#15 98.57 /src/Server/Program.cs(9,7): error CS0246: The type or namespace name 'SomeApp' could not be found (are you missing a using directive or an assembly reference?) [/src/Server/Server.csproj]
#15 98.57 1 Warning(s)
#15 98.57 1 Error(s)
#15 98.57
#15 98.57 Time Elapsed 00:01:35.02
------
executor failed running [/bin/sh -c dotnet build "Server.csproj" -c Release -o /app/build]: exit code: 1
The Dockerfile which is used:
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["Server/Server.csproj", "Server/"]
RUN dotnet restore "Server/Server.csproj"
COPY . .
WORKDIR "/src/Server"
RUN dotnet build "Server.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Server.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Server.dll"]
EXPOSE 5004
The directory looks as follows:
\Trunk\Tools\Dashboard (my application with its own solution)
\Trunk\SomeApp (other application with its own solution)
+- SomeApp.sln
+- Api ("project" folder)
+- SomeApp.Api.csproj
Project reference in dashboard.sln:
<ItemGroup>
<ProjectReference Include="..\..\..\SomeApp\Api\SomeApp.Api.csproj" />
</ItemGroup>
I tried to build a Docker image of my application, and I expected to get a Docker image, so I could build a Docker container. I totally get that it can't find the 'SomeApp' application, because I'm not pushing it to the Docker image. But how could I solve this problem?
(Edit: removed unreadable JPG and added cmd lines. Also added Dockerfile, which is used at the moment. For the minimal reproducible example there are two project solutions needed, with the same file structure as shown above. )
c#
asp.net
docker
dockerfile
docker-image
0 Answers
Your Answer