Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# dotnet还原在docker compose构建中极其缓慢_C#_Docker_.net Core - Fatal编程技术网

C# dotnet还原在docker compose构建中极其缓慢

C# dotnet还原在docker compose构建中极其缓慢,c#,docker,.net-core,C#,Docker,.net Core,我有一个.NET核心项目,我正在构建一个docker映像。Dockerfile如下所示: FROM mcr.microsoft.com/dotnet/core/sdk:3.0-alpine AS restore WORKDIR /tmp/build COPY ./*.sln . COPY ./*/*.csproj ./ # Put project files back into their own project directories RUN for file in $(ls *.csproj

我有一个.NET核心项目,我正在构建一个docker映像。Dockerfile如下所示:

FROM mcr.microsoft.com/dotnet/core/sdk:3.0-alpine AS restore
WORKDIR /tmp/build
COPY ./*.sln .
COPY ./*/*.csproj ./
# Put project files back into their own project directories
RUN for file in $(ls *.csproj); do mkdir -p ${file%.*}/ && mv $file ${file%.*}/; done
RUN dotnet restore

# Copy in the source files
FROM restore AS build
WORKDIR /tmp/build
COPY . .
RUN dotnet publish -o output MyApp/MyApp.csproj

FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-alpine AS runtime
WORKDIR /app
COPY --from=build /tmp/build/output .
ENTRYPOINT [ "dotnet", "MyApp.dll"]
如果我将
cd
放入目录并运行
dotnet restore
,包将很快恢复,不会出现任何问题。但是,当它在Docker中点击构建过程的
rundotnetrestore
行时,restore命令的运行速度非常慢,有时甚至超时


我只能假设这是Docker网络连接的一个问题,但我不知道从哪里开始。这是在Linux上,特别是在Deepin上。

我相信这可能与尚未发布的dotnet core v3有关

生成以下dockerfile:

FROM mcr.microsoft.com/dotnet/core/sdk:2.2-alpine AS restore
WORKDIR /tmp/build
COPY . .
RUN dotnet restore

FROM restore AS build
WORKDIR /tmp/build
COPY . .
RUN dotnet publish -o output restore-example.csproj

FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-alpine AS runtime
WORKDIR /app
COPY --from=build /tmp/build/output .
ENTRYPOINT [ "dotnet", "restore-example.dll"]
FROM mcr.microsoft.com/dotnet/core/sdk:3.0-alpine AS restore
WORKDIR /tmp/build
COPY . .
RUN dotnet restore

FROM restore AS build
WORKDIR /tmp/build
COPY . .
RUN dotnet publish -o output restore-example.csproj

FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-alpine AS runtime
WORKDIR /app
COPY --from=build /tmp/build/output .
ENTRYPOINT [ "dotnet", "restore-example.dll"]
我得到的构建时间是12秒

$ docker system prune -f && time docker build .
Deleted Images:
deleted: sha256:af0270527dd0dd2a5e371daa395fa91f834b1573eab831725e37c1c98fcd91d7
deleted: sha256:5d5762859e232d5f010b5584d76fc5c4dcf1eb3779b50099d0844ebf08329588
deleted: sha256:906be7cd6a27a7bd5a712061faca0d02ae36cc7c1cd007e11e222f0970c7cce1
deleted: sha256:143ec3415424e99d0518cf39eaf20b5aac2f6b1c6d6edcebd788ad92cdbd14aa
deleted: sha256:2a391aaba15427d9979bc1aa57f2af03f891a055ef6e740e34f7739d64f4e593
deleted: sha256:16576c0f378d7c0450c8e9d8268e6840065e2534d8701c023075ae7b4a351a7b
deleted: sha256:ccf12511b61cab62eae3b6067cde13728d9145924e3d8266d3d765bd2014c1db
deleted: sha256:e7149dfa101cdb975b2c21fdb4f5eaa9ffb4fa5e0b720089937bce200b192353
deleted: sha256:0e1be0f142e24fac1e510ad8047ac0eee813d0583d76351bdb42cc82cbf7e8bc
deleted: sha256:8e1f0aa0f65c5bad1168eed9b9e213f6c3a2610de069e3ae6a1afc262d141eb9
deleted: sha256:85182a03f99e21e91afd9f17d373bb44d502bab3d01ff362f45cca39d6fe04d3
deleted: sha256:52ed4afff3095e3ac5b2e34a1aabce7b4407a0b95550b82657f62e56f8009585
deleted: sha256:841a8ff534c2efabee04f3e035ed7b565a5ae95eec8d16e9fdff00d7862260cb
deleted: sha256:a9aaff5c95ce5444732deef867c986cba25cd760f67bd557885d1a604c1649ab
deleted: sha256:b01c24cc26f155c7017baf482d9b7d11140cf122ca061b2241c8c5a5e734986e
deleted: sha256:863e4585da1623aa9568a58b306fb31ffaa28038b50f2354a4356f56fb9deaa6

Total reclaimed space: 67.36MB
Sending build context to Docker daemon  71.17kB
Step 1/12 : FROM mcr.microsoft.com/dotnet/core/sdk:2.2-alpine AS restore
 ---> a4262c5dc8c3
Step 2/12 : WORKDIR /tmp/build
 ---> Running in fbf8121ee1f4
Removing intermediate container fbf8121ee1f4
 ---> 11d67baed4b4
Step 3/12 : COPY . .
 ---> 703e0db87403
Step 4/12 : RUN dotnet restore
 ---> Running in bc4fc4e36282
  Restore completed in 6.14 sec for /tmp/build/restore-example.csproj.
Removing intermediate container bc4fc4e36282
 ---> e0eb73b57f9b
Step 5/12 : FROM restore AS build
 ---> e0eb73b57f9b
Step 6/12 : WORKDIR /tmp/build
 ---> Running in da50ef82948b
Removing intermediate container da50ef82948b
 ---> 3215dff1d63b
Step 7/12 : COPY . .
 ---> b5898cfbf57e
Step 8/12 : RUN dotnet publish -o output restore-example.csproj
 ---> Running in 14ad93b89253
Microsoft (R) Build Engine version 16.2.32702+c4012a063 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 41.27 ms for /tmp/build/restore-example.csproj.
  restore-example -> /tmp/build/bin/Debug/netcoreapp2.2/restore-example.dll
  restore-example -> /tmp/build/output/
Removing intermediate container 14ad93b89253
 ---> 5ec8c744e4a5
Step 9/12 : FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-alpine AS runtime
 ---> 829fb2904a07
Step 10/12 : WORKDIR /app
 ---> Running in a8b276c6229d
Removing intermediate container a8b276c6229d
 ---> 0aed3e9a3a94
Step 11/12 : COPY --from=build /tmp/build/output .
 ---> 36f9141d0c21
Step 12/12 : ENTRYPOINT [ "dotnet", "restore-example.dll"]
 ---> Running in 8e54f498b5bf
Removing intermediate container 8e54f498b5bf
 ---> 7bca25c5d0bb
Successfully built 7bca25c5d0bb

real    0m12.359s
user    0m0.049s
sys 0m0.050s
生成以下dockerfile:

FROM mcr.microsoft.com/dotnet/core/sdk:2.2-alpine AS restore
WORKDIR /tmp/build
COPY . .
RUN dotnet restore

FROM restore AS build
WORKDIR /tmp/build
COPY . .
RUN dotnet publish -o output restore-example.csproj

FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-alpine AS runtime
WORKDIR /app
COPY --from=build /tmp/build/output .
ENTRYPOINT [ "dotnet", "restore-example.dll"]
FROM mcr.microsoft.com/dotnet/core/sdk:3.0-alpine AS restore
WORKDIR /tmp/build
COPY . .
RUN dotnet restore

FROM restore AS build
WORKDIR /tmp/build
COPY . .
RUN dotnet publish -o output restore-example.csproj

FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-alpine AS runtime
WORKDIR /app
COPY --from=build /tmp/build/output .
ENTRYPOINT [ "dotnet", "restore-example.dll"]
我的构建时间为1m+(并且至少有一个构建超时):

我正在运行最新的Fedora 30安装

Linux localhost.localdomain 5.2.9-200.fc30.x86_64 #1 SMP Fri Aug 16 21:37:45 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
和docker v19

Docker version 19.03.1, build 74b1e89

在我的例子中,它有助于在运行“docker build”命令之前删除
/bin
/obj
文件夹

这是我的
dockerfile
,用于一个名为
GoD\u backend的.NET Core 5.0 API bakend

GoD\u build
dotnet publish
作为输入的中间文件夹
GoD\u back
dotnet发布
放置结果的文件夹

# https://hub.docker.com/_/microsoft-dotnet
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
COPY /src/* /GoD_build 
RUN dotnet publish -c release -o /GoD_back /GoD_build/GoD_backend.csproj

# final stage/image
FROM mcr.microsoft.com/dotnet/runtime:5.0
WORKDIR /GoD_build
COPY --from=build /GoD_back .
ENTRYPOINT ["dotnet", "GoD_backend.dll"]

在这里有类似的问题,我找不到一个方法来加快这一点,到目前为止。。。