简体   繁体   English

为什么 docker build 在我的复制路径前面加上临时目录?

[英]Why is docker build prefixing my copy path with a temp directory?

Here is the DockerFile.这是 DockerFile。

FROM microsoft/aspnet:4.7
ARG source
WORKDIR /inetpub/wwwroot
COPY ${source:-obj/Docker/publish} .

And here is the error.这是错误。

Error
Building a.enterpriseextservices
Service 'a.enterpriseextservices' failed to build: COPY failed: 
GetFileAttributesEx \\?\C:\Users\jesmiller-AM\AppData\Local\Temp\docker-
builder587295999\obj\Docker\publish: The system cannot find the file specified..

For more troubleshooting information, go to 
http://aka.ms/DockerToolsTroubleshooting    docker-compose  C:\Program Files 
(x86)\Microsoft Visual Studio\2017\Community\MSBuild\Sdks\Microsoft.Docker.Sdk\build\Microsoft.VisualStudio.Docker.Compose.targets  349 

I have published the project to the obj/Docker/publish folder.我已将项目发布到 obj/Docker/publish 文件夹。 Here is my docker-compose file.这是我的 docker-compose 文件。 I used the docker-compose up command from the folder where the docker-compose.yml file is located.我使用了 docker-compose.yml 文件所在文件夹中的 docker-compose up 命令。

version: '3'

services:
  a.web.familyconnection:
    image: a.web.familyconnection
    build:
      context: .\FamilyConnection
      dockerfile: Dockerfile
  b.enterpriseextservices:
    image: b.enterpriseextservices
    build:
      context: .\Framework\b.EnterpriseExtServices
      dockerfile: Dockerfile

I had the same issue.我遇到过同样的问题。 Turned out I made a silly mistake.结果我犯了一个愚蠢的错误。 I added the following to my .dockerignore file, just out of habit when setting up a new project:我在我的 .dockerignore 文件中添加了以下内容,只是在设置新项目时出于习惯:

bin
obj
.vs
.git

Then I tried running this in my Dockerfile然后我尝试在我的 Dockerfile 中运行它

COPY ./bin/publish/ .

Docker gave the strange tmp path error, because it was falling back to that path since I told it to ignore my /bin folder. Docker 给出了奇怪的 tmp 路径错误,因为它正在回退到那个路径,因为我告诉它忽略我的 /bin 文件夹。 Once I copied to a different publish path (not bin), the problem went away.一旦我复制到不同的发布路径(不是 bin),问题就消失了。

It looks like your path to the folders, or where you've published your code at may be incorrect.看起来您的文件夹路径或您发布代码的位置可能不正确。 The project should be published in the obj/Docker/publish folder inside of the respective folders defined by context该项目应发布在context定义的相应文件夹内的obj/Docker/publish文件夹context

Using an example docker-compose.yml :使用示例docker-compose.yml

version: "3"

services:
  foo:
    build: ./foo
  bar:
    build: ./bar

And Dockerfile :Dockerfile

FROM jaydorsey/ruby-2.4.1

COPY ${source:-obj/Docker/publish} .

And a tree structure like this:和这样的树结构:

.
├── Dockerfile
├── bar
│   └── Dockerfile
├── docker-compose.yml
├── foo
│   └── Dockerfile
└── obj
    └── Docker
        └── publish

When I run docker-compose build I get the following error当我运行docker-compose build ,出现以下错误

Building foo
Step 1/2 : FROM jaydorsey/ruby-2.4.1
 ---> b79899b232f6
Step 2/2 : COPY ${source:-obj/Docker/publish} .
ERROR: Service 'foo' failed to build: COPY failed: stat /var/lib/docker/tmp/docker-builder186649811/obj/Docker/publish: no such file or directory

This isn't identical to yours, since I'm running macOS, but very similar.这与您的不同,因为我运行的是 macOS,但非常相似。 You'll note the temporary file location (which is an internal Docker artifact of how it's copying files around) and the similarity in the docker-build<randomstring> path您会注意到临时文件的位置(这是它如何复制文件的内部 Docker 工件)以及docker-build<randomstring>路径中的相似性

However, if I create the obj/Docker/publish folders underneath each respective subfolder ( context ), the docker-compose build command works fine.但是,如果我在每个相应的子文件夹 ( context ) 下创建obj/Docker/publish文件夹,则docker-compose build命令可以正常工作。

.
├── Dockerfile
├── bar
│   ├── Dockerfile
│   └── obj
│       └── Docker
│           └── publish
├── docker-compose.yml
├── foo
│   ├── Dockerfile
│   └── obj
│       └── Docker
│           └── publish
└── obj
    └── Docker
        └── publish

Please check that the folder you've published exists under the contexts as noted, and not in the root.请检查您发布的文件夹是否存在于上述上下文中,而不是根目录中。

I still believe this is a path issue as noted in the error message.我仍然认为这是错误消息中指出的路径问题。 I hope this provides some context that helps you debug the root cause.我希望这提供了一些帮助您调试根本原因的上下文。

Can you please confirm your file & folder layout?你能确认你的文件和文件夹布局吗? I'm fairly certain it's path related because of the error message.由于错误消息,我相当确定它与路径相关。 I haven't done any Docker for Windows work either but I'd also double-check your default path using the correct slash (forward vs backward)我也没有为 Windows 做过任何 Docker 工作,但我也会使用正确的斜杠(向前与向后)仔细检查您的默认路径

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Docker Aspnet core 设置物理目录路径 - Docker Aspnet core Setting physical directory path Windows docker映像构建在创建目录时挂起 - Windows docker image build hangs on creating a directory 在预构建事件中从解决方案目录和项目目录复制 - copy from solution directory and project directory in pre build event 如何使用 Dockerfile 将目录从 docker 容器复制到主机? - How to copy a directory from docker container to host using Dockerfile? 在目录中搜索文件夹并在新的Excel工作簿中复制其路径 - Search Folder in Directory and copy its path in new excel work book 当我在虚拟目录中创建临时文件时,IIS应用程序池崩溃 - IIS Application pool crashes when i create temp files in my virtual directory 带有 Linux Docker 的 ASP.NET 自动生成“服务&#39;无法构建:复制失败:stat /var/lib/docker/tmp/docker-builder” - ASP.NET with Linux Docker autogenerated "Service 'failed to build: COPY failed: stat /var/lib/docker/tmp/docker-builder" 为什么我的代码无法在项目中找到路径? - Why my code can not find the path in project? 如何自动清除zedgraph图像的临时目录? - How to auto clear temp directory for zedgraph images? ASP.NET拒绝访问临时目录 - ASP.NET Access to the temp directory is denied
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM