-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dotnet publish --no-restore
fails during docker build
even if the packages are already restored in a web app with dependent class library
#37291
Comments
Hello! Just wanted to chime in and mention that I also struggle with the exact same problem, and am observing the exact same behaviour, e.g. removing My case differs in that my project are using .NET 7! I have the following Dockerfile, where the ASPNET project FROM mcr.microsoft.com/dotnet/sdk:7.0-bullseye-slim AS build
WORKDIR /src
COPY ["nuget.config", "./"]
COPY ["Example.Service/Example.Service.csproj", "Example.Service/"]
COPY ["Example.Data/Example.Data.csproj", "Example.Data/"]
RUN dotnet restore "Example.Service/Example.Service.csproj"
COPY ["Example.Service/", "Example.Service/"]
COPY ["Example.Data/", "Example.Data/"]
FROM build AS publish
WORKDIR /src/Example.Service
RUN dotnet publish "Example.Service.csproj" \
--configuration release \
--no-restore \
--output /app/publish
FROM mcr.microsoft.com/dotnet/aspnet:7.0-bullseye-slim AS runtime
WORKDIR /app
COPY --from=publish /app/publish .
EXPOSE 80
ENTRYPOINT ["dotnet", "Example.Service.dll"] Building with this Dockerfile yields me the following error message:
My dockerfile is inspired from:
From my
|
I have the same issue. This is my dockerfile: FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG TARGETARCH
WORKDIR /source
COPY *.csproj .
RUN dotnet restore -a $TARGETARCH
COPY . .
RUN dotnet publish -c Release -a $TARGETARCH --no-restore -o /app
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY --from=build /app .
ENV ASPNETCORE_HTTP_PORTS=80
EXPOSE 80
USER $APP_UID
ENTRYPOINT ["./api"] This is the error I see:
Here's the output of $ dotnet --info
.NET SDK:
Version: 8.0.100
Commit: 57efcf1350
Workload version: 8.0.100-manifests.6c33ef20
Runtime Environment:
OS Name: ubuntu
OS Version: 20.04
OS Platform: Linux
RID: linux-x64
Base Path: /usr/share/dotnet/sdk/8.0.100/
.NET workloads installed:
Workload version: 8.0.100-manifests.6c33ef20
There are no installed workloads to display.
Host:
Version: 8.0.0
Architecture: x64
Commit: 5535e31a71
.NET SDKs installed:
6.0.404 [/usr/share/dotnet/sdk]
7.0.101 [/usr/share/dotnet/sdk]
8.0.100 [/usr/share/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.12 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.1 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.0 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.12 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.1 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.0 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Other architectures found:
None
Environment variables:
Not set
global.json file:
Not found
Learn more:
https://aka.ms/dotnet/info
Download .NET: I'm running on Windows 10 with WSL and Docker Desktop. I build using the following docker command:
My project at the moment is a simple hello world project based on the sample here with some simple Swagger boilerplate. The same commit was working fine but has begun failing on my host machine due to the aforementioned issue. It builds fine in Github Actions. It builds fine when I remove the |
I just had this exact issue, after a lot of fiddling round I finailly got it working by adding this .dockerignore to my project root with this Dockerfile
Don't think it was one of the other things I tried, so posting this in case it helps anyone else. |
I'm seeing the same thing. In my case, I'm hoping to restore the packages outside of Docker to avoid complications with the Azure credentials provider not being available in the container. If I do add and configure the Azure credentials provider in the container manually then I'm able to restore as you'd expect, but then a subsequent build with |
Just to update, so I've reproduced this without a Docker build be involved at all. This basically seems to be an issue with using the .NET SDK on Linux. The With my affected project, the following steps reproduce the issue:
i.e. run the restore and build within the container. Doing the same on Windows - i.e. step 2 and 3 - doesn't have the issue. |
HI ms could you put some attention here please, the amount of fiddling to get a build to work is ... dying for attention. |
Describe the bug
dotnet publish --no-restore
fails duringdocker build
even if the packages are already restored. The app is a .NET 8 web api with a dependent class library.To Reproduce
All the steps in reproducing this issue are documented in this minimalistic repro project:
https://github.com/akhanalcs/docker-with-classlib
In nutshell, the issue is that it's not possible to create a docker image without restoring the packages twice, once during
dotnet restore
and other duringdotnet publish
. If you use--no-restore
flag indotnet publish
even AFTER doingdotnet restore
, the image build fails with this error:Exceptions (if any)
Further technical details
dotnet --info
JetBrains Rider 2023.2.3
The text was updated successfully, but these errors were encountered: