从我的项目文件创建新的 docker 图像时出错
Error in creating new docker image from my project file
在我的 windows 10 机器上,当我试图为我的 solution/project 创建一个 docker 图像时,出现以下错误(这是完整的日志,错误位于结束)
Sending build context to Docker daemon 1.363MB
Step 1/20 : FROM mcr.microsoft.com/dotnet/core/aspnet:2.1-stretch-slim AS base
---> bbfbcd874370
Step 2/20 : WORKDIR /app
---> Using cache
---> 6aa13d5c0c78
Step 3/20 : EXPOSE 80
---> Using cache
---> 80df41e66b51
Step 4/20 : EXPOSE 443
---> Using cache
---> e6b48dd0ebe8
Step 5/20 : FROM mcr.microsoft.com/dotnet/core/sdk:2.1-stretch AS build
---> 83e4b70d6dc1
Step 6/20 : ARG BuildConfiguration=Release
---> Using cache
---> 1f78c91d39f1
Step 7/20 : WORKDIR /src
---> Using cache
---> 213aa5f648e4
Step 8/20 : COPY ["NuGet.config", "."]
---> Using cache
---> d8843fccc7af
Step 9/20 : COPY ["MyProj.csproj", "ServiceProject/"]
---> Using cache
---> af245be6312e
Step 10/20 : RUN dotnet restore --configfile NuGet.config "MyProj.csproj"
---> Running in 0582b332eab7
MSBUILD : error MSB1009: Project file does not exist.
Switch: MyProj.csproj
The command '/bin/sh -c dotnet restore --configfile NuGet.config "MyProj.csproj"' returned a non-zero code: 1
Dockerfile如下
FROM mcr.microsoft.com/dotnet/core/aspnet:2.1-stretch-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:2.1-stretch AS build
ARG BuildConfiguration=Release
WORKDIR /src
COPY ["NuGet.config", "."]
COPY ["MyProj.csproj", "NewProj/"]
RUN dotnet restore --configfile NuGet.config "MyProj.csproj"
COPY . .
WORKDIR "/src/MyService"
RUN dotnet build "MyProj.csproj" -c ${BuildConfiguration} -o /app --no-restore
FROM build AS publish
ARG BuildConfiguration=Release
RUN dotnet publish "MyProj.csproj" -c ${BuildConfiguration} -o /app --no-restore
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "MyProj.dll"]
文件夹中存在文件 MyProj.csproj
是的,我是 AdminMode 中的 运行 powershell
我也试过给全路径,也没用
我尝试了 docker 文档和 Whosebug,但没有提到这个错误。如果可能,请提供逐步解决方案,在此先感谢
将我的评论作为答案 - 您最初的问题是 csproj 文件的位置。你运行
COPY ["NuGet.config", "."]
COPY ["MyProj.csproj", "NewProj/"]
因此 MyProj.csproj 位于“NewProj/”。所以当你 运行
RUN dotnet restore --configfile NuGet.config "MyProj.csproj"
找不到 MyProj。选项是提供项目文件的正确路径或将其复制到与 nuget.config.
相同的位置
至于你的以下错误 - 看起来像
/usr/share/dotnet/sdk/2.1.801/NuGet.targets(525,5): error : Value cannot be null or empty string. [/src/MyProj.csproj]
/usr/share/dotnet/sdk/2.1.801/NuGet.targets(525,5): error : Parameter
name: username [/src/MyProj.csproj]
需要“用户名”才能访问您正在使用的 nuget 提要之一。尝试将 username/password 添加到您的 nuget.config 文件 - https://docs.microsoft.com/en-us/nuget/reference/nuget-config-file#package-source-sections
在 Visual Studio 中创建 project/solution 时, 别名答案或什至可能没有深入到此路径,只需选中显示启用 Docker 支持的框。这将自动生成 docker 文件供您使用,您可以避免这些问题。
在我的 windows 10 机器上,当我试图为我的 solution/project 创建一个 docker 图像时,出现以下错误(这是完整的日志,错误位于结束)
Sending build context to Docker daemon 1.363MB
Step 1/20 : FROM mcr.microsoft.com/dotnet/core/aspnet:2.1-stretch-slim AS base
---> bbfbcd874370
Step 2/20 : WORKDIR /app
---> Using cache
---> 6aa13d5c0c78
Step 3/20 : EXPOSE 80
---> Using cache
---> 80df41e66b51
Step 4/20 : EXPOSE 443
---> Using cache
---> e6b48dd0ebe8
Step 5/20 : FROM mcr.microsoft.com/dotnet/core/sdk:2.1-stretch AS build
---> 83e4b70d6dc1
Step 6/20 : ARG BuildConfiguration=Release
---> Using cache
---> 1f78c91d39f1
Step 7/20 : WORKDIR /src
---> Using cache
---> 213aa5f648e4
Step 8/20 : COPY ["NuGet.config", "."]
---> Using cache
---> d8843fccc7af
Step 9/20 : COPY ["MyProj.csproj", "ServiceProject/"]
---> Using cache
---> af245be6312e
Step 10/20 : RUN dotnet restore --configfile NuGet.config "MyProj.csproj"
---> Running in 0582b332eab7
MSBUILD : error MSB1009: Project file does not exist.
Switch: MyProj.csproj
The command '/bin/sh -c dotnet restore --configfile NuGet.config "MyProj.csproj"' returned a non-zero code: 1
Dockerfile如下
FROM mcr.microsoft.com/dotnet/core/aspnet:2.1-stretch-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:2.1-stretch AS build
ARG BuildConfiguration=Release
WORKDIR /src
COPY ["NuGet.config", "."]
COPY ["MyProj.csproj", "NewProj/"]
RUN dotnet restore --configfile NuGet.config "MyProj.csproj"
COPY . .
WORKDIR "/src/MyService"
RUN dotnet build "MyProj.csproj" -c ${BuildConfiguration} -o /app --no-restore
FROM build AS publish
ARG BuildConfiguration=Release
RUN dotnet publish "MyProj.csproj" -c ${BuildConfiguration} -o /app --no-restore
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "MyProj.dll"]
文件夹中存在文件 MyProj.csproj 是的,我是 AdminMode 中的 运行 powershell 我也试过给全路径,也没用
我尝试了 docker 文档和 Whosebug,但没有提到这个错误。如果可能,请提供逐步解决方案,在此先感谢
将我的评论作为答案 - 您最初的问题是 csproj 文件的位置。你运行
COPY ["NuGet.config", "."]
COPY ["MyProj.csproj", "NewProj/"]
因此 MyProj.csproj 位于“NewProj/”。所以当你 运行
RUN dotnet restore --configfile NuGet.config "MyProj.csproj"
找不到 MyProj。选项是提供项目文件的正确路径或将其复制到与 nuget.config.
相同的位置至于你的以下错误 - 看起来像
/usr/share/dotnet/sdk/2.1.801/NuGet.targets(525,5): error : Value cannot be null or empty string. [/src/MyProj.csproj]
/usr/share/dotnet/sdk/2.1.801/NuGet.targets(525,5): error : Parameter name: username [/src/MyProj.csproj]
需要“用户名”才能访问您正在使用的 nuget 提要之一。尝试将 username/password 添加到您的 nuget.config 文件 - https://docs.microsoft.com/en-us/nuget/reference/nuget-config-file#package-source-sections
别名答案或什至可能没有深入到此路径,只需选中显示启用 Docker 支持的框。这将自动生成 docker 文件供您使用,您可以避免这些问题。