具有Docker文件支持的Visual Studio-没有此类文件或目录

时间:2018-09-06 20:24:20

标签: docker visual-studio-2017 dockerfile

我是Docker的新手。当我创建一个具有linux docker支持的空ASP.NET Core MVC项目时,Visual Studio会生成以下Dockerfile:

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

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

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

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

启动PowerShell时,更改目录并运行命令

docker build .

我收到错误-没有这样的文件或目录。

Sending build context to Docker daemon  910.8kB
Step 1/16 : FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
 ---> bf6acba27669
Step 2/16 : WORKDIR /app
 ---> Using cache
 ---> a48d00205739
Step 3/16 : EXPOSE 80
 ---> Using cache
 ---> 93b2ba2ff3cc
Step 4/16 : FROM microsoft/dotnet:2.1-sdk AS build
 ---> 9d32878ab9fe
Step 5/16 : WORKDIR /src
 ---> Using cache
 ---> 5c5247716e9f
Step 6/16 : COPY DockerTest/DockerTest.csproj DockerTest/
COPY failed: stat /var/lib/docker/tmp/docker-builder159418839/DockerTest/DockerTest.csproj: no such file or directory

1 个答案:

答案 0 :(得分:7)

这是我的错。我应该从项目根目录运行此命令:

docker build -f "DockerTest/Dockerfile" .