在ASP.NET Core中构建docker:“没有此类文件或目录”;错误 [英] Build docker in ASP.NET Core: "no such file or directory" error
问题描述
构建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 .
您有什么想法吗?
推荐答案
之所以如此,是因为您没有发布解决方案。错误消息是不言自明的:
It's happening because you didn't published your solution. The error message is self-explanatory:
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:“没有此类文件或目录”;错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!