问题描述
我在构建 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:“没有这样的文件或目录";错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)