✅ Error while Dockerizing an ASP.NET project which references another project.

So i am having an ASP.NET project called ScoreManagementAPI which references another project containing EF Core Entities Models and Context called Entities with the directory structure as in the screenshot. But the thing is when i try to dockerize the ScoreManagementAPI project with the following content inside ScoreManagementAPI/Dockerfile
# FROM mcr.microsoft.com/dotnet/sdk:8.0-nanoserver-1809 AS build
FROM mcr.microsoft.com/dotnet/aspnet:8.0.3-alpine3.18-amd64 AS base
WORKDIR /app
EXPOSE 8080
EXPOSE 8081
EXPOSE 80

# Building the core project
FROM mcr.microsoft.com/dotnet/sdk:8.0.203-alpine3.18-amd64 AS build
WORKDIR /src
RUN mkdir api Entities
COPY ["./ScoreManagementAPI/ScoreManagementAPI.csproj", "/src/api"]
COPY ["./Entities/Entities.csproj", "/src/Entities"]
RUN dotnet restore "./api/ScoreManagementAPI.csproj"
COPY ./ScoreManagementAPI ./api
COPY ./Entities /src/Entities

WORKDIR /src/api
RUN dotnet build "ScoreManagementAPI.csproj" -c Release -o /src/api/build


# Publish the application
FROM build as publish
RUN dotnet publish "ScoreManagementAPI.csproj" -c Release ./publish
# FROM mcr.microsoft.com/dotnet/sdk:8.0-nanoserver-1809 AS build
FROM mcr.microsoft.com/dotnet/aspnet:8.0.3-alpine3.18-amd64 AS base
WORKDIR /app
EXPOSE 8080
EXPOSE 8081
EXPOSE 80

# Building the core project
FROM mcr.microsoft.com/dotnet/sdk:8.0.203-alpine3.18-amd64 AS build
WORKDIR /src
RUN mkdir api Entities
COPY ["./ScoreManagementAPI/ScoreManagementAPI.csproj", "/src/api"]
COPY ["./Entities/Entities.csproj", "/src/Entities"]
RUN dotnet restore "./api/ScoreManagementAPI.csproj"
COPY ./ScoreManagementAPI ./api
COPY ./Entities /src/Entities

WORKDIR /src/api
RUN dotnet build "ScoreManagementAPI.csproj" -c Release -o /src/api/build


# Publish the application
FROM build as publish
RUN dotnet publish "ScoreManagementAPI.csproj" -c Release ./publish
No description
No description
No description
7 Replies
ScriptKidding
ScriptKiddingOP8mo ago
I am always hit with this error
=> ERROR [publish 1/1] RUN dotnet publish "ScoreManagementAPI.csproj" -c Release ./publish
------
> [publish 1/1] RUN dotnet publish "ScoreManagementAPI.csproj" -c Release ./publish:
0.642 MSBuild version 17.9.6+a4ecab324 for .NET
0.647 MSBUILD : error MSB1008: Only one project can be specified.
0.647 Full command line: '/usr/share/dotnet/sdk/8.0.203/MSBuild.dll -maxcpucount -verbosity:m -restore -target:Publish --property:_IsPublishing=true -property:Configuration=Release -property:DOTNET_CLI_DISPUBLISH_AND_PACK_RELEASE=true ScoreManagementAPI.csproj ./publish -distributedlogger:Microsoft.DotNet.Tools.MSBuild.MSBuildLogger,/usr/share/dotnet/sdk/8.0.203/dotnet.dll*Microsoft.DotNet.Tools.MSBuild.MSBuildrdingLogger,/usr/share/dotnet/sdk/8.0.203/dotnet.dll'
0.647 Switches appended by response files:
0.647 Switch: ./publish
------
Dockerfile:25
--------------------
23 | # Publish the application
24 | FROM build as publish
25 | >>> RUN dotnet publish "ScoreManagementAPI.csproj" -c Release ./publish
26 |
27 | ENTRYPOINT [ "ls", "/src/Entities" ]
--------------------
ERROR: failed to solve: process "/bin/sh -c dotnet publish \"ScoreManagementAPI.csproj\" -c Release ./publish" did not complete successfully: exit code: 1

View build details: docker-desktop://dashboard/build/default/default/ldjohf1twrrr0ulw9vu5jbcax
=> ERROR [publish 1/1] RUN dotnet publish "ScoreManagementAPI.csproj" -c Release ./publish
------
> [publish 1/1] RUN dotnet publish "ScoreManagementAPI.csproj" -c Release ./publish:
0.642 MSBuild version 17.9.6+a4ecab324 for .NET
0.647 MSBUILD : error MSB1008: Only one project can be specified.
0.647 Full command line: '/usr/share/dotnet/sdk/8.0.203/MSBuild.dll -maxcpucount -verbosity:m -restore -target:Publish --property:_IsPublishing=true -property:Configuration=Release -property:DOTNET_CLI_DISPUBLISH_AND_PACK_RELEASE=true ScoreManagementAPI.csproj ./publish -distributedlogger:Microsoft.DotNet.Tools.MSBuild.MSBuildLogger,/usr/share/dotnet/sdk/8.0.203/dotnet.dll*Microsoft.DotNet.Tools.MSBuild.MSBuildrdingLogger,/usr/share/dotnet/sdk/8.0.203/dotnet.dll'
0.647 Switches appended by response files:
0.647 Switch: ./publish
------
Dockerfile:25
--------------------
23 | # Publish the application
24 | FROM build as publish
25 | >>> RUN dotnet publish "ScoreManagementAPI.csproj" -c Release ./publish
26 |
27 | ENTRYPOINT [ "ls", "/src/Entities" ]
--------------------
ERROR: failed to solve: process "/bin/sh -c dotnet publish \"ScoreManagementAPI.csproj\" -c Release ./publish" did not complete successfully: exit code: 1

View build details: docker-desktop://dashboard/build/default/default/ldjohf1twrrr0ulw9vu5jbcax
Anyone knows why ? please help. Also i executed the build command by standing at the Backend folder then running the following line
docker build -t score -f .\ScoreManagementAPI\Dockerfile .
docker build -t score -f .\ScoreManagementAPI\Dockerfile .
mldisibio
mldisibio8mo ago
Paths inside the docker file are relatvie to the docker file itself, not to the location you are running the command from
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX8mo ago
Docker Documentation
Overview of the get started guide
Get started with the Docker basics in this comprehensive overview, You'll learn about containers, images, and how to containerize your first application.
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX8mo ago
ARG DOTNET_VERSION=8.0
FROM mcr.microsoft.com/dotnet/sdk:${DOTNET_VERSION} AS build
WORKDIR /sln

COPY ./*.sln ./nuget.config ./

# Copy the main source project files
COPY src/*/*.csproj ./
RUN for file in $(ls *.csproj); do mkdir -p src/${file%.*}/ && mv $file src/${file%.*}/; done

# Copy the test project files
COPY test/*/*.csproj ./
RUN for file in $(ls *.csproj); do mkdir -p test/${file%.*}/ && mv $file test/${file%.*}/; done

RUN dotnet restore

# possible FROM .... for multi stage here
COPY . .
RUN dotnet build

RUN dotnet publish --project src/Your.Project/Your.Project.csproj -c Release -o /publish --no-restore

# final stage/image
ARG DOTNET_VERSION=8.0
FROM mcr.microsoft.com/dotnet/aspnet:${DOTNET_VERSION}
WORKDIR /app
COPY --from=build /publish .
ENTRYPOINT ["dotnet", "Your.Project.dll"]
ARG DOTNET_VERSION=8.0
FROM mcr.microsoft.com/dotnet/sdk:${DOTNET_VERSION} AS build
WORKDIR /sln

COPY ./*.sln ./nuget.config ./

# Copy the main source project files
COPY src/*/*.csproj ./
RUN for file in $(ls *.csproj); do mkdir -p src/${file%.*}/ && mv $file src/${file%.*}/; done

# Copy the test project files
COPY test/*/*.csproj ./
RUN for file in $(ls *.csproj); do mkdir -p test/${file%.*}/ && mv $file test/${file%.*}/; done

RUN dotnet restore

# possible FROM .... for multi stage here
COPY . .
RUN dotnet build

RUN dotnet publish --project src/Your.Project/Your.Project.csproj -c Release -o /publish --no-restore

# final stage/image
ARG DOTNET_VERSION=8.0
FROM mcr.microsoft.com/dotnet/aspnet:${DOTNET_VERSION}
WORKDIR /app
COPY --from=build /publish .
ENTRYPOINT ["dotnet", "Your.Project.dll"]
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server