Docker复制命令失败

Docker Copy Command fails

我是 Docker 的新手,而 运行 Docker 文件

我的Docker文件

FROM microsoft/dotnet:2.2.0-preview1-aspnetcore-runtime AS base 
WORKDIR /app

FROM microsoft/dotnet:2.2.100-preview1-sdk AS build
WORKDIR /DineshVisualStudio/Autofac-interceptor/AutofacModule/Autofac.interface.ConcactFactory
COPY Autofac.Interface.ConcatFactory.csproj project/
WORKDIR /Autofac-interceptor/project
RUN dotnet restore
COPY /Autofac.interface.Concactfactory .
RUN dotnet build -c Release -o /app

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

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["Autofac.Interface.ConcatFactory.exe"]

当 运行 docker build -t myappfactory . 失败时。我在 COPY 命令中尝试了多种路径组合,但没有成功。

我正在使用 Visual Studio 2017 并安装了 Docker 工具

这是我的文件夹结构 My folder structure with the code having docker file

当 运行 docker build -t autofacinterface . 我收到一条错误消息:

failed to create file . System cannot find the file specified.

我正在使用 Cmd 从我当前工作的 .csproj 文件夹中构建 docker。

D:\DineshVisualStudio\Autofac-Interceptor\AutofacModule\Autofac.Interface.ConcatFactory>docker build -t autofacinterfaceconcatfactory .
Sending build context to Docker daemon  4.608kB
Step 1/15 : FROM microsoft/dotnet:2.2.0-preview1-aspnetcore-runtime AS base
---> 2df5940c47f7
Step 2/15 : WORKDIR /app
---> Using cache
---> f4d2190d9b44
Step 3/15 : FROM microsoft/dotnet:2.2.100-preview1-sdk AS build
---> af242cb10bf0
Step 4/15 : WORKDIR /DineshVisualStudio/Autofac- 
interceptor/AutofacModule/Autofac.interface.ConcactFactory
---> Using cache
---> dbf15787395b
Step 5/15 : COPY /Autofac.Interface.ConcatFactory.csproj project/
COPY failed: CreateFile \?\C:\ProgramData\Docker\tmp\docker- 
builder138146052\COPY: The system cannot find the file specified.

在@Mike 建议后我遇到了这个问题:

D:\DineshVisualStudio\Autofac-Interceptor\AutofacModule\Autofac.Interface.ConcatFactory>docker build -t myappfact .
Step 6/15 : WORKDIR /Autofac-interceptor/project
Step 7/15 : RUN dotnet restore
---> Running in 9e91df3e68a3
MSBUILD : error MSB1003: Specify a project or solution file. The current 
working directory does not contain a project or solution file.
The command 'cmd /S /C dotnet restore' returned a non-zero code: 1
Step 5/15 : COPY COPY

您的 Dockerfile 中是否连续两次出现 COPY 一词?

我认为您不需要 COPY /Autofac.Interface.ConcatFactory.csproj 中的前导 /。源文件是相对于当前工作目录的,并且您之前已经调用了 WORKDIR

https://docs.docker.com/engine/reference/builder/#copy

命令“COPY /Autofac.Interface.ConcatFactory.csproj project/”失败。我建议您阅读有关 COPY here 命令的更多信息。如果您从文件夹 "D:\DineshVisualStudio\Autofac- Interceptor\AutofacModule\Autofac.Interface.ConcatFactory" 运行 docker build,请使用命令“COPY . .”。