gpt4 book ai didi

c# - VS2019 Docker 支持和 Dockerfile 失败

转载 作者:行者123 更新时间:2023-12-04 12:17:09 25 4
gpt4 key购买 nike

VS2019,创建了一个全新的 mvc 应用程序,支持 Windows Docker。

Dockerfile 内容(从模板创建):

FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-nanoserver-1809 AS base
WORKDIR /app
EXPOSE 80

FROM mcr.microsoft.com/dotnet/core/sdk:2.2-nanoserver-1809 AS build
WORKDIR /src
COPY ["mvc1.csproj", "mvc1/"]
RUN dotnet restore "mvc1/mvc1.csproj"
COPY . .
WORKDIR "/src/mvc1"
RUN dotnet build "mvc1.csproj" -c Release -o /app

FROM build AS publish
RUN dotnet publish "mvc1.csproj" -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "mvc1.dll"]

enter image description here

当我执行:
docker build -t mvc1 .

我收到以下错误:

C:\Program Files\dotnet\sdk\2.2.401\NuGet.targets(123,5): error : Unable to load the service index for source https://api.nuget.org/v3/index.json. [C:\src\mvc1\mvc1.csproj] C:\Program Files\dotnet\sdk\2.2.401\NuGet.targets(123,5): error : No such host is known [C:\src\mvc1\mvc1.csproj] The command 'cmd /S /C dotnet restore "mvc1/mvc1.csproj"' returned a non-zero code: 1



编辑:
我已将此行添加到 Dockerfile:
RUN ping google.com

并得到:
Step 4/17 : RUN ping google.com
---> Running in 6633175b21a8
Ping request could not find host google.com. Please check the name and try again.

编辑 2:

所以,当我编辑我的 .csproj 文件并删除这一行时,结果是:
        <Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
</PropertyGroup>


<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
<!-- REMOVED -->
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.7.12" />
<!-- REMOVED -->
</ItemGroup>

</Project>

它确实有效。这是为什么?

最佳答案

我有同样的问题。此链接解决了我的问题:
https://improveandrepeat.com/2019/09/how-to-fix-network-errors-with-docker-and-windows-containers/
我的默认以太网适配器没有最低指标
检查:

Get-NetIPInterface -AddressFamily IPv4 | Sort-Object -Property InterfaceMetric -Descending
设置:
Set-NetIPInterface -InterfaceAlias 'Ethernet' -InterfaceMetric 4

关于c# - VS2019 Docker 支持和 Dockerfile 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57791748/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com