用于Windows构建的Docker为COPY添加了前缀`/ var / lib / docker / tmp /`? [英] Docker for Windows building added prefix `/var/lib/docker/tmp/` for COPY?

查看:233
本文介绍了用于Windows构建的Docker为COPY添加了前缀`/ var / lib / docker / tmp /`?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了适用于Windows的Docker,并使用Visual Studio 2017创建了一个新的具有docker支持的Asp.net核心应用程序(我尚未进行任何更改)。但是,docker build报告以下错误。 Dockerfile是否正确?

I've installed Docker for Windows and created a new Asp.net core application with docker support using Visual Studio 2017(I haven't made any change yet). However, docker build reported the following error. Is the Dockerfile correct?


PS C:\source\repos\myProj\ProcessFiles> docker build .
Sending build context to Docker daemon  1.178MB
Step 1/17 : FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
 ---> 04aae08f15c5
Step 2/17 : WORKDIR /app
 ---> Using cache
 ---> 135955e04284
Step 3/17 : EXPOSE 34746
 ---> Using cache
 ---> 85fd0075aa42
Step 4/17 : EXPOSE 44398
 ---> Using cache
 ---> 7e3d5526f601
Step 5/17 : FROM microsoft/dotnet:2.1-sdk AS build
 ---> 7c3e298d40ac
Step 6/17 : WORKDIR /src
 ---> Using cache
 ---> b395ba27d8f9
Step 7/17 : COPY ProcessFiles/ProcessFiles.csproj ProcessFiles/
COPY failed: stat /var/lib/docker/tmp/docker-builder662645761/ProcessFiles/ProcessFiles.csproj: no such file
 or directory

这是Visual Studio自动生成的 Dockerfile 。错误发生在 COPY ProcessFiles / ProcessFiles.csproj ProcessFiles / 行上。

Here is the Dockerfile automatically generated by Visual Studio. The error occurred on the line COPY ProcessFiles/ProcessFiles.csproj ProcessFiles/.

FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 34746
EXPOSE 44398

FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY ProcessFiles/ProcessFiles.csproj ProcessFiles/
RUN dotnet restore ProcessFiles/ProcessFiles.csproj
COPY . .
WORKDIR /src/ProcessFiles
RUN dotnet build ProcessFiles.csproj -c Release -o /app

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

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

这是Visual Studio输出。 (不包括有关设置AWS的行)。

Here is the Visual Studio output. (The lines about setting AWS were excluded).


Inspecting Dockerfile to figure how to build project and docker image
... Skip building project since it is done as part of Dockerfile
Executing docker build
... invoking 'docker build', working folder 'C:\source\repos\myProj\ProcessFiles, docker file C:\source\repos\myProc\ProcessFiles\Dockerfile, image name processfiles:latest'
... docker build: Sending build context to Docker daemon  1.178MB
... docker build: COPY failed: stat /var/lib/docker/tmp/docker-builder225959758/ProcessFiles/ProcessFiles.csproj: no such file or directory
... docker build: Step 1/17 : FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
... docker build:  ---> 04aae08f15c5
... docker build: Step 2/17 : WORKDIR /app
... docker build:  ---> Using cache
... docker build:  ---> 135955e04284
... docker build: Step 3/17 : EXPOSE 34746
... docker build:  ---> Using cache
... docker build:  ---> 85fd0075aa42
... docker build: Step 4/17 : EXPOSE 44398
... docker build:  ---> Using cache
... docker build:  ---> 7e3d5526f601
... docker build: Step 5/17 : FROM microsoft/dotnet:2.1-sdk AS build
... docker build:  ---> 7c3e298d40ac
... docker build: Step 6/17 : WORKDIR /src
... docker build:  ---> Using cache
... docker build:  ---> b395ba27d8f9
... docker build: Step 7/17 : COPY ProcessFiles/ProcessFiles.csproj ProcessFiles/
Error executing "docker build"
Attempting to clean up any ELB resources created for the failed deployment
Unknown error publishing container to AWS

以下是目录 C:\source\repos\中的文件myProj 。文件 Dockerfile C: repos\myProj\ProcessFile\ 下。

Here are the files in directory C:\source\repos\myProj. The file Dockerfile is under C:\source\repos\myProj\ProcessFile\. Should it be moved one level up?


Mode   Name
----   ----
d----- bin
d----- obj
d----- ProcessFiles
-a---- .dockerignore
-a---- .gitattributes
-a---- .gitignore
-a---- docker-compose.dcproj
-a---- docker-compose.override.yml
-a---- docker-compose.yml
-a---- myProc.sln


推荐答案

运行构建命令时

docker build .

在该命令中表示构建上下文,该上下文将发送到(可能是远程的)泊坞窗引擎。所有 COPY ADD 命令必须来自该目录内(或来自具有多阶段构建的上一阶段) 。您还可以使用 .dockerignore 文件从此上下文中排除文件。 tmp目录是由docker唯一生成的内部目录,由该构建上下文组成。

The . in that command indicates the "build context" that gets sent to the (possibly remote) docker engine. All of the COPY and ADD commands must be from inside this directory (or from a previous stage with multi stage builds). You can also exclude files from this context using the .dockerignore file. The tmp directory is a uniquely generated internal directory of docker's consisting of this build context.

要解决您的问题,您需要确保ProcessFiles / ProcessFiles.csproj存在于

从中运行构建的目录,并且没有从 .dockerignore 文件的上下文中将其排除。

To fix your issue, you need to make sure ProcessFiles/ProcessFiles.csproj exists in the directory where you run your build from, and that you didn't exclude it from the context with the .dockerignore file.

编辑:根据您的评论,将复制命令更改为:

based on your comments, change your copy command to:

COPY ProcessFiles.csproj ProcessFiles/

这篇关于用于Windows构建的Docker为COPY添加了前缀`/ var / lib / docker / tmp /`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆