简体   繁体   English

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

[英]Build docker in ASP.NET Core: "no such file or directory" error

I'm getting an error when I build my docker.我在构建 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

Here's my Dockerfile.这是我的 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"

and I run a command:我运行一个命令:

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

Do you have any ide what is wrong?你有什么想法吗?

It's happening because you didn't published your solution.这是因为您没有发布您的解决方案。 The error message is self-explanatory:错误消息是不言自明的:

no such file or directory

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.默认情况下,当您向 ASP.NET Core Visual Studio 2017 项目添加Docker 支持时,它会创建一堆docker-compose.yml文件,其中一个是处理构建过程docker-compose.ci.build.yml Then, when you build the project through Visual Studio, full docker-compose pipeline is executed.然后,当您通过 Visual Studio 构建项目时,将执行完整的docker-compose管道。

The contents of docker-compose.ci.build.yml , are similiar to this (it depends on custom config and project names obviously): docker-compose.ci.build.yml的内容与此类似(这显然取决于自定义配置和项目名称):

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"

As you can see in the last line, there is a dotnet publish command invoked, which actually builds & publishes your project.正如您在最后一行中看到的,调用了一个dotnet publish命令,它实际上构建和发布您的项目。

So the solution for your issue , will be just building the project before calling docker:因此,您的问题解决方案将只是在调用 docker 之前构建项目:

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

When you use the option "Add Docker Support" in Visual Studio 2017, VS generates a bunch of docker-compose files and Dockerfiles.在 Visual Studio 2017 中使用“添加 Docker 支持”选项时,VS 会生成一堆 docker-compose 文件和 Dockerfile。 As Marcin Zablocki mentioned, one of these is docker-compose.ci.build.yml .正如 Marcin Zablocki 提到的,其中之一是docker-compose.ci.build.yml

To stay in line with the Docker philosophy, you can use a docker container to publish your project.为了与 Docker 理念保持一致,您可以使用 docker 容器来发布您的项目。 To publish your project you would take the following steps:要发布您的项目,您将执行以下步骤:

  1. git clone/pull your project & cd into the root dir git clone/pull your project & cd 到根目录
  2. Publish your project with docker-compose -f docker-compose.ci.build.yml up使用docker-compose -f docker-compose.ci.build.yml up发布您的项目
  3. Start your project with docker-compose up使用docker-compose up启动您的项目

I have encountered situations where the Dockerfile of your main project is giving problems.我遇到过主项目的Dockerfile出现问题的情况。 This happens with FROM microsoft/aspnetcore:1.1 , you can change it to FROM microsoft/aspnetcore:1.1.2 or whatever version is needed for your project.这发生在FROM microsoft/aspnetcore:1.1 ,您可以将其更改为FROM microsoft/aspnetcore:1.1.2或您的项目所需的任何版本。

如果你已经发布了你的项目并且因为目录错误而面临这个问题,只需将 docker 文件向上移动一个文件夹并将其放在 *.sln 文件旁边。

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

相关问题 具有ASP.NET Core库的Docker容器 - Docker container with ASP.NET Core libraries Docker-发布Asp.Net Core - Docker - publish Asp.Net Core Asp.net 内核中的 Active Directory - Active Directory in Asp.net core 对于 Windows 构建服务器上现有的 ASP.NET 核心 MVC 项目,如何在不干扰早期构建管道阶段的情况下定位 Docker 容器? - For existing ASP.NET Core MVC project on Windows build server, how to target a Docker container without disturbing earlier build pipeline stages? ASP.NET Core (.NET 5) + Angular 11 = 在空项目上构建错误 - ASP.NET Core (.NET 5) + Angular 11 = build error on empty project 从 Docker 容器内的 ASP.Net Core 应用程序(Blazor)连接到 Azure SQL 服务器时出错 - Error when connecting to Azure SQL Server from an ASP.Net Core App (Blazor) inside a Docker container 上传文件 - ASP.NET Core MVC - Uploading file - ASP.NET Core MVC ASP.NET Core和Entityframwork迁移错误 - Asp.net core and Entityframwork migration error Visual Studio 2017 ASP.NET Core 中的 TFS 构建问题/错误 - TFS Build issue/error in visual Studio 2017 ASP.NET Core 我可以在Docker容器中发布不是ASP.NET 5或ASP.NET Core的.Net应用程序吗? - Can I publish a .Net application which is not ASP.NET 5 or ASP.NET Core in Docker containers?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM