[英]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:
要发布您的项目,您将执行以下步骤:
git clone/pull
your project & cd into the root dir git clone/pull
your project & cd 到根目录docker-compose -f docker-compose.ci.build.yml up
docker-compose -f docker-compose.ci.build.yml up
发布您的项目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.