在 ASP.NET Core 中构建 docker:“没有这样的文件或目录";错误

Build docker in ASP.NET Core: quot;no such file or directoryquot; error(在 ASP.NET Core 中构建 docker:“没有这样的文件或目录;错误)

本文介绍了在 ASP.NET Core 中构建 docker:“没有这样的文件或目录";错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在构建 docker 时遇到错误.

I'm getting an error when I build my docker.

Sending build context to Docker daemon 3.584 kB
Step 1/8 : FROM microsoft/aspnetcore:1.1
 ---> 2628aaa7b8cf
Step 2/8 : ENV ASPNETCORE_URLS "http://*:5000"
 ---> Using cache
 ---> 5dffde204fef
Step 3/8 : ENV ASPNETCORE_ENVIRONMENT "Development"
 ---> Using cache
 ---> 3064358bc0eb
Step 4/8 : ARG source
 ---> Using cache
 ---> 4159d0eb78c0
Step 5/8 : WORKDIR /app
 ---> Using cache
 ---> 61a394c84304
Step 6/8 : EXPOSE 5000
 ---> Using cache
 ---> c7c2309f7085
Step 7/8 : COPY ${source:-obj/Docker/publish} .
lstat obj/Docker/publish: no such file or directory

这是我的 Dockerfile.

Here's my Dockerfile.

FROM microsoft/aspnetcore:1.1
ENV ASPNETCORE_URLS="http://*:5000"
ENV ASPNETCORE_ENVIRONMENT="Development"
ARG source
WORKDIR /app
EXPOSE 5000
COPY ${source:-obj/Docker/publish} .
ENTRYPOINT ["dotnet", "ProjectTestApi.dll"

然后我运行一个命令:

$ docker build -t my-docker-image-test .

你有什么问题吗?

推荐答案

发生这种情况是因为您没有发布解决方案.错误消息一目了然:

no such file or directory

默认情况下,当您向 ASP.NET Core Visual Studio 2017 项目添加 Docker 支持 时,它会创建一堆 docker-compose.yml 文件,其中一个它们是处理构建过程的 docker-compose.ci.build.yml.然后,当您通过 Visual Studio 构建项目时,会执行完整的 docker-compose 管道.

By default, when you add Docker support to you ASP.NET Core Visual Studio 2017 project, it creates a bunch of docker-compose.yml files, one of them is docker-compose.ci.build.yml which handles the build process. Then, when you build the project through Visual Studio, full docker-compose pipeline is executed.

docker-compose.ci.build.yml的内容,与此类似(显然取决于自定义配置和项目名称):

The contents of docker-compose.ci.build.yml, are similiar to this (it depends on custom config and project names obviously):

version: '2'

services:
  ci-build:
    image: microsoft/aspnetcore-build:1.0-1.1
    volumes:
      - .:/src
    working_dir: /src
    command: /bin/bash -c "dotnet restore ./SolutionName.sln && dotnet publish ./SolutionName.sln -c Release -o ./obj/Docker/publish"

正如您在最后一行看到的,调用了一个 dotnet publish 命令,它实际上构建了 &发布您的项目.

As you can see in the last line, there is a dotnet publish command invoked, which actually builds & publishes your project.

所以您的问题的解决方案,将只是在调用 docker 之前构建项目:

So the solution for your issue, will be just building the project before calling docker:

dotnet publish ./SolutionName.sln -c Release -o ./obj/Docker/publish
docker build -t my-docker-image-test .

这篇关于在 ASP.NET Core 中构建 docker:“没有这样的文件或目录";错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:在 ASP.NET Core 中构建 docker:“没有这样的文件或目录";错误

基础教程推荐