Dotnet 还原 Docker 失败 [英] Dotnet restore Docker fail
本文介绍了Dotnet 还原 Docker 失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Docker 和命令 dotnet restore 有问题.我有 docker 文件:
There is problem with Docker and command dotnet restore. I have the docker file:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["AuthAPI/AuthAPI.csproj", "AuthAPI/"]
COPY ["CommonCoreLibrary/CommonCoreLibrary.csproj", "CommonCoreLibrary/"]
RUN dotnet restore "AuthAPI/AuthAPI.csproj"
COPY . .
WORKDIR "/src/AuthAPI"
RUN dotnet build "AuthAPI.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "AuthAPI.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
COPY wait /wait
RUN chmod +x /wait
COPY /cert /root/.dotnet/https
ENTRYPOINT /wait && dotnet AuthAPI.dll
和docker compose文件:
and docker compose file:
authapi:
image: ${DOCKER_REGISTRY-}authapi
build:
context: .
dockerfile: AuthAPI/Dockerfile
networks:
- peopleapp
environment:
WAIT_HOSTS: db:5432
WAIT_HOSTS_TIMEOUT: 300
ports:
- "8002:443"
当我运行命令时
docker-compose -f "docker-compose.yml" build
我有一个错误
Step 10/23 : RUN dotnet restore "AnalyticAPI/AnalyticAPI.csproj"
---> Running in 2d29e1367d51
Determining projects to restore...
/usr/share/dotnet/sdk/3.1.300/NuGet.targets(128,5): error : Unable to load the service index for source https://api.nuget.org/v3/index.json. [/src/AnalyticAPI/AnalyticAPI.csproj]
/usr/share/dotnet/sdk/3.1.300/NuGet.targets(128,5): error : Connection refused [/src/AnalyticAPI/AnalyticAPI.csproj]
ERROR: Service 'analyticapi' failed to build: The command '/bin/sh -c dotnet restore "AnalyticAPI/AnalyticAPI.csproj"' returned a non-zero code: 1
有时它工作正常.有连接被拒绝的警告,但恢复成功.我使用 Windows 10 + Hyper-V + Docker Desktop + Linux Containers + NET Core 3.1.
Sometimes it works fine. There are warning about Connection refused, but restoring is success. I use Windows 10 + Hyper-V + Docker Desktop + Linux Containers + NET Core 3.1.
推荐答案
我遇到了类似的问题.它对我有用:
I had a similar problem. It's works for me:
- 在恢复前向 dockerfile 添加 curl 命令:
- 运行 curl https://api.nuget.org/v3/index.json -k
- 运行 dotnet 恢复AuthAPI/AuthAPI.csproj"
- 构建镜像
- 从 dockerfile 中删除 curl 命令
- 重新构建镜像
这篇关于Dotnet 还原 Docker 失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文