English 中文(简体)
Docker犯了错误,“没有计算切身钥匙:没有发现”——在视觉演播室进行罚款。
原标题:Docker gets error "failed to compute cache key: not found" - runs fine in Visual Studio

我用视频演播室制作了一个多克书。 视力演播室只进行罚款,现在Im试图从视窗本身建造这种节目(docker Building .,我尝试了许多组合。 然而,我有以下错误:

> [build 3/7] COPY [client/client.csproj, client/]:
------
failed to compute cache key: "/client/client.csproj" not found: not found

当我改为<代码>时,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

我做了什么错误? 我将多克赖特改为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"]
最佳回答

The way Visual Studio does it is a little bit odd.

Instead of launching docker build in the folder with the Dockerfile, it launches in the parent folder and specifies the Dockerfile with the -f option.

我正在利用“清点”项目(为另一个问题找到最低限度的解决办法),并触及同样的情况。

我的血清项目

WorkerService2  ("solution" folder)
   +- WorkerService2.sln
   +- WorkserService2  ("project" folder)
       +- DockerFile
       +- WorkerService2.csproj
       +- ... other program files

因此,请上<>expect。

cd Workerservice2WorkerService2
docker build .

但我收到了你的错误信息。

 => ERROR [build 3/7] COPY [WorkerService2/WorkerService2.csproj, WorkerService2/]                                                                                                                        0.0s
------
 > [build 3/7] COPY [WorkerService2/WorkerService2.csproj, WorkerService2/]:
------
failed to compute cache key: "/WorkerService2/WorkerService2.csproj" not found: not found

相反,取向母体目录,附.sln文档,并使用-f选项,具体指明Dockerfile在子里使用:

cd Workerservice2
docker build -f WorkerService2Dockerfile --force-rm -t worker2/try7 .

docker run -it worker2/try7    

Note the final dot on the docker Building direct.

对码头而言,指挥的最后一个部分是Docker将同案档案的地点。 Usually,这是Dockerfile的夹,但对于VS是如何做的,这有点不同。 在此情况下, do本特有-f。 任何途径(例如<代码>COPY 指示书)都与具体地点有关。

I got to this stage by inspecting the output of the build process, with verbosity set to Detailed. If you choose Tools / Options / Projects and Solutions / Build and Run you can adjust the build output verbosity, I made mine Detailed.


I think I ve worked out why Visual Studio does it this way. It allows the project references in the same solution to be copied in.

如果设置了<代码>docker,从项目夹中建造,则 do无法在解决方案中找到任何其他项目<代码>COPY。 但是,随着目前的名录是解决方案的夹,你可以把参考项目(文件夹)复制到你的码头建设过程中。

问题回答

查阅<代码>.dockerignore文档。 可能的话,它忽视了复印指挥所需的档案,而且你没有计算重大错误。

.dockerignore may be configured to minimize the files sent to docker for performance and security:

* 
!dist/

第1行<代码>*将所有档案都解冻。 第二行<代码>!dist/ 允许<代码>dist 夹

This can cause unexpected behavior:

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

带带和停机。

我也有同样的问题,在增加多克支持时,我把多克环境置于Windows。 即使在视力演播室的演播中也出现了错误。 由于我的Docker在Windows Subsystem为LC(WSL)运行,我把环境改变为六氯环己烷。

然后,我返回机场,管理指挥。

I was able to resolve this by moving to the Solutions folder (Root folder).

And I did docker build like this:

docker build -t containername/tag -f ProjectFolder/Dockerfile .

接着,我做了<代码>多克操作:

docker run containername/tag

Asking for a directory that does not exist throws this error.

在我的案件中,我曾尝试过。

 > [stage-1  7/14] COPY /.ssh/id_rsa.pub /.ssh/:
------
failed to compute cache key: "/.ssh/id_rsa.pub" not found: not found

我忘记在项目目录中添加<代码>/ssh。 在您的情形下,您应检查<代码>/client是否确实是您的Dockerfile建立背景的子体。

以下指挥机构没有遵守<条码>,无法计算切身钥匙:没有见:

docker build -t tag-name:v1.5.1 - <Dockerfile

在将指挥改为以下指挥时:

docker build -t tag-name:v1.5.1 -f Dockerfile .

在我的案件中,我发现,码头建筑在名录上是敏感的,因此我在《公约》缔约方会议的指示中写了文件/bin/release/net5.0/publish,而且没有同样的错误,我刚刚改为/bin/Release/net5.0/publish,并且工作。

Error : failed to compute cache key: "src" not found: not found

in my case , folder/file excluded in .dockerignore

  1. after resolving file from dockerignore able to create image.

就我而言,我有这样的情况:

  FROM mcr.microsoft.com/dotnet/aspnet:5.0
  COPY bin/Release/net5.0/publish/ app/
  WORKDIR /app
  ENTRYPOINT ["dotnet", "MyApi.dll"]

最后,我认识到,我有bin <>/strong> 夹在我的手.中。

I had a similar issues: Apparently, docker roots the file system during build to the specified build directory for security reasons. As a result, COPY and ADD cannot refer to arbitrary locations on the host file system. Additionally, there are other issues with syntax peculiarities. What eventually worked was the following:

COPY ./script_file.sh  /
RUN /script_file.sh

I had the same issue. In my case there was a wrong directory specified. My Dockerfile was:

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS publish
WORKDIR /app
COPY . .
RUN dotnet publish -c Release -o publish/web src/MyApp/MyApp.csproj

FROM mcr.microsoft.com/dotnet/aspnet:5.0
WORKDIR /app
COPY --from=publish publish/web .
EXPOSE 80
CMD ASPNETCORE_URLS=http://*:$PORT dotnet MyApp.dll

然后,我认识到,在第二层建筑阶段,我试图复制名录中的项目档案:<编码> publish/web:

COPY --from=publish publish/web .

But as I specified workdir /app in the first stage, my files are located in that directory in image filesystem, so changing path from publish/web to app/publish/web resolved my issue.

So my final working Dockerfile is:

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS publish
WORKDIR /app
COPY . .
RUN dotnet publish -c Release -o publish/web src/MyApp/MyApp.csproj

FROM mcr.microsoft.com/dotnet/aspnet:5.0
WORKDIR /app
COPY --from=publish app/publish/web .
EXPOSE 80
CMD ASPNETCORE_URLS=http://*:$PORT dotnet MyApp.dll

在我的案件中,在档案名称中出现了一个 s形的白色空间。

------
 > [3/3] COPY init.sh ./:
------
failed to compute cache key: "/init.sh" not found: not found

因此,档案实际上称为“init.sh”,而不是“init.sh”。

The nginx.conf file must be included to be published. Right Click on the nginx.conf file and open the Properties. Change "Copy to output directory" to "Copy always"

我也面临同样的问题。

理由是Docker案卷中DL文件的名称是敏感的。

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY MyFirstMicroService.csproj .
RUN dotnet restore
COPY . .
RUN dotnet publish -c release -o /app

FROM mcr.microsoft.com/dotnet/aspnet:5.0
WORKDIR /app
COPY --from=build /app .
ENTRYPOINT ["dotnet", "**MyFirstMicroService.dll**"]

This .dll name should match your .csproj file.

当你不向缔约方会议提供恰当的途径时,情况也是如此。 最重要的一点是,工技研中心指挥打开了集装箱的夹,而不是放在窗户的探索者身上(因此,它没有影响你为缔约方会议指挥而指明的道路)。

In my Case, i was doing mistake in / and . Let me explain Open your dockerfile (it should be named as dockerfile only, not DockerFile or Dockerfile). You may have something like this- FROM mcr.microsoft.com/dotnet/runtime:5.0 COPY binRelease et5.0publish . ENTRYPOINT ["dotnet", "HelloDocker.dll"]

Replace COPY binRelease et5.0publish . to COPY bin/Release/net5.0/publish .

in my case, it was a wrong Build with PATH configuration e.g. Docker build context

  1. Simple docker script
    docker build . 
    
    where . is path to build context
  2. Gradle+Docker
    docker {
        dependsOn build
        dependsOn dockerFilesCopy
        name "${project.name}:${project.version}"
        files "build" // path to build context
    }
    
  3. Gradle+GitHub action
    name: Docker build and push
    
    on:
      push:
        branches: [ main ]
    
    # ...
    
    jobs:
      build:
        runs-on: ubuntu-latest
    
        # ...
    
        steps:
          - name: Checkout
            uses: actions/checkout@v2
    
         # ...
    
          - name: Build and export to Docker
            uses: docker/build-push-action@v2
            with:
              # ...
              file: src/main/docker/Dockerfile      
              context: ./build                      # path to build context
    

In my case, with Angular project, my project was in the folder called ex: My-Folder-Project and I was putting on Dockerfile COPY --from=publish app/dist/My-Folder-Project . But of course the correct thing is put the "name" in your package.json like COPY --from=publish app/dist/name-in-package.json .

在我的案件中,我改变了情况,也改变了Dockerfile在 do公司内部的道路。 y:

services:
    server:
        # inheritance structru
        extends:
            file: ../../docker-compose.server.yml
        # I recommend you to play with this paths
        build:
            context: ../../
            dockerfile: ./apps/${APP_NAME}/Dockerfile
        ...

I run into a similar issue where I was attempting to run the docker build command. I created a folder called "Docker" and inside of it another folder called "getting-started". I kept running into the error:

failed to compute cache key: “/public” not found

我认识到,我应从“启动”的夹而不是“cker”手中指挥。 我这样做了。

Laravel用户......

我在操作<代码>docker compose up时就犯了这一错误,这是由于在我的公共文件夹中存在着一个存储链条束的束缚。

指挥部在拆除了该通道后,成功执行。

我也谈到这一错误,首先,它从Dodockerignore删除了一些档案。

After that, I used a variable and haven t used $ operator to resolve it. Added $ before "{variable}", it worked for me.

任何人在马台电离层电离层电离层后奋力抗衡,都可以在台 desktop上排除罗塞塔的 em。

It s all due to an error in the dockerignore file. If you check that the file has ignore target then leave it out





相关问题
Why running a service as Local System is bad on windows?

I am trying to find out the difference between difference service account types. I tumbled upon this question. The answer was because it has powerful access to local resources, and Network Service ...

Programmatically detect Windows cluster configuration?

Does anyone know how to programatically detect that a Windows server is part of a cluster? Further, is it possible to detect that the server is the active or passive node? [Edit] And detect it from ...

get file icon for Outlook appointment (.msg)

I ve read Get File Icon used by Shell and the other similar posts - and already use SHFileInfo to get the associated icon for any given extension, and that works great. However, Outlook uses ".msg" ...

Identifying idle state on a windows machine

I know about the GetLastInputInfo method but that would only give me the duration since last user input - keyboard or mouse. If a user input was last received 10 minutes ago, that wouldn t mean the ...

Terminating a thread gracefully not using TerminateThread()

My application creates a thread and that runs in the background all the time. I can only terminate the thread manually, not from within the thread callback function. At the moment I am using ...