dotnet paket restore failed while building docker image
See original GitHub issueDescription
The command “dotnet paket restore” exited with code 1.
Repro steps
Please provide the steps required to reproduce the problem
-
Install paket as .Net core Local tool
POCs\HelloDI> dotnet new tool-manifest
POCs\HelloDI> dotnet tool install paket
POCs\HelloDI> dotnet paket init
-
add /bin & /obj to .dockerignore file at root folder
.git
**/bin/
**/obj/
-
add package to .csproject
POCs\HelloDI> cd .\src\HelloDI.Console\
POCs\HelloDI\src\HelloDI.Console> dotnet paket add Microsoft.Extensions.Configuration.Json --interactive
-
Docker file contents (
src\HelloDI.Console\Dockerfile
)
ARG VERSION=3.1-alpine3.12
FROM mcr.microsoft.com/dotnet/core/sdk:$VERSION as build-env
WORKDIR /HelloDI.Console
COPY /src/HelloDI.Console/*.csproj .
RUN dotnet restore
COPY . .
RUN dotnet publish src/HelloDI.Console/HelloDI.Console.csproj --output /out/ --configuration Release
FROM mcr.microsoft.com/dotnet/core/runtime:$VERSION as runtime
WORKDIR /HelloDI.Console
COPY --from=build-env /out .
ENTRYPOINT ["dotnet", "HelloDI.Console.dll"]
- Local Msbuild successful.
POCs\HelloDI\src\HelloDI.Console> cd ..\..
POCs\HelloDI> dotnet build
Output
Microsoft (R) Build Engine version 16.6.0+5ff7b0c9e for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore...
Paket version 5.247.4
The last restore is still up to date. Nothing left to do.
Performance:
- Runtime: 228 milliseconds
Paket version 5.247.4
Starting restore process.
Performance:
- Runtime: 1 second
Restored D:\@aviWin10.workspace\@POCs\HelloDI\tests\HelloDI.Console.Tests\HelloDI.Console.Tests.csproj (in 9.3 sec).
1 of 2 projects are up-to-date for restore.
.....
- Error during-Build Docker image
POCs\HelloDI> docker build -t hello-di/console:0.1 -f ./src/HelloDI.Console/dockerfile .
Output
Step 5/11 : RUN dotnet restore
---> Using cache
---> a3b73898202f
Step 6/11 : COPY . .
---> 65085b0c2d6f
Step 7/11 : RUN dotnet publish src/HelloDI.Console/HelloDI.Console.csproj --output /out/ --configuration Release
---> Running in f16be0b6c474
Microsoft (R) Build Engine version 16.6.0+5ff7b0c9e for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore...
Run "dotnet tool restore" to make the "paket" command available.
/HelloDI.Console/.paket/Paket.Restore.targets(171,5): error MSB3073: The command "dotnet paket restore" exited with code 1.
[/HelloDI.Console/src/HelloDI.Console/HelloDI.Console.csproj]
The command '/bin/sh -c dotnet publish src/HelloDI.Console/HelloDI.Console.csproj --output /out/ --configuration Release' returned a non-zero code: 1
Expected behavior
dotnet paket restore
should execute successfully.
Actual behavior
error at dotnet paket restore
Known workarounds
remove **/obj/
from .dockerignore
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
asp.net core - dotnet restore fails from Docker container
I was able to get around this issue by setting the http_proxy in my Dockerfile. ARG HTTP_PROXY="http://username:password@proxy.example.com:8080".
Read more >Dotnet restore fails when building in docker container
When doing docker restore --disable-parallel it works without any problems, but takes 20 minutes to build that small project.
Read more >Solving flaky dotnet restore issue only on Docker
When I build a Dockerfile, at the part of the dotnet restore I encountered this issue. However, On my colleague's PC, it works...
Read more >NuGet restore failing in Docker Container
The Problem. We have a very simple .Net Core MVC solution. It has the following NuGet packages.
Read more >Rider Dockerfile Build fails with NU1301 and does not restore ...
So when I execute docker build -f Dapr101.Backend/Dockerfile -t dapr101backend --rm everything works. However, still from within Rider build ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I encountered the same issue and it seems that during build-time it explicitly invokes
dotnet-paket
instead ofdotnet paket
. I created a symlink in my Dockerfile to ensure that the file can be run. My Dockerfile looks like this:The important line is the
RUN echo ...
to create thedotnet-paket
command. I am not a big fan of usingfind
, because it may result in multiple binaries. I did use it to not break my Dockerfile when I upgrade paket.Just tried above suggestion : As I am trying to containerize a single project from multi-project solution
POCs\HelloDI> docker build -t hello-di/console:0.1 -f ./src/HelloDI.Console/dockerfile .
Expected behavior
Successfully tagged hello-di/console:0.1
Actual behavior
dotnet publish
unable to locate file -/HelloDI/src/HelloDI.Console/obj/project.assets.json
even though it is generated by previously executeddotnet restore
.(verified the file existence by logging into container usingdocker run -it
)Known workarounds
--no-restore
fromdotnet publish
command in above dockerfile.RUN dotnet publish src/HelloDI.Console/HelloDI.Console.csproj --output /out/ --configuration Release
–no-restore