我使用 Visual Studio 生成了一个 Dockerfile。它在 Visual Studio 中运行得很好,现在我正在尝试从 Windows 本身构建它(docker build .
,并且我尝试了很多组合)。但我收到以下错误:
> [build 3/7] COPY [client/client.csproj, client/]:
------
failed to compute cache key: "/client/client.csproj" not found: not found
当我将副本更改为./client.csproj
它确实继续,然后我得到:
=> ERROR [build 7/7] RUN dotnet build "client.csproj" -c Release -o /app/build 3.3s
------
> [build 7/7] RUN dotnet build "client.csproj" -c Release -o /app/build:
#15 0.652 Microsoft (R) Build Engine version 16.8.3+39993d9d for .NET
#15 0.652 Copyright (C) Microsoft Corporation. All rights reserved.
#15 0.652
#15 1.169 Determining projects to restore...
#15 1.483 All projects are up-to-date for restore.
#15 3.231 CSC : error CS5001: Program does not contain a static 'Main' method suitable for an entry point [/src/client/client.csproj]
#15 3.240
#15 3.240 Build FAILED.
#15 3.240
#15 3.240 CSC : error CS5001: Program does not contain a static 'Main' method suitable for an entry point [/src/client/client.csproj]
#15 3.240 0 Warning (5)
#15 3.240 1 Error (5)
#15 3.240
#15 3.240 Time Elapsed 00:00:02.51
-----
executor failed running [/bin/sh -c dotnet build "client.csproj" -c Release -o /app/build]: exit code: 1
我究竟做错了什么?我把 Docker Linux 改成了 Windows,改了WSL,并重新启动一切。
#See https://aka.ms/containerfastmode to understand how Visua...
FROM mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build
WORKDIR /src
COPY ["client/client.csproj", "client/"]
RUN dotnet restore "client/client.csproj"
COPY . .
WORKDIR "/src/client"
RUN dotnet build "client.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "client.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet', "client.dll"]
检查你的.dockerignore
文件。它可能会忽略复制命令所需的文件,并且您会出现无法计算缓存密钥错误。
.dockerignore
为了性能和安全性,可以配置为最小化发送到 docker 的文件:
*
!dist/
第一行*
禁止所有文件。第二行!dist/
允许dist
folder
这可能会导致意外行为:
FROM nginx:latest
# Fails because of * in .dockerignore
# failed to compute cache key: "/nginx.conf.spa" not found: not found
# Fix by adding `!nginx.conf.spa` to .dockerignore
COPY nginx.conf.spa /etc/nginx/nginx.conf
RUN mkdir /app
# Works because of !dist/ in .dockerignore
COPY dist/spa /app
腰带和吊带。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)