带有 docker 和 .NET Core 2.0 的 VSTS CI/CD - 复制失败 [英] VSTS CI/CD with docker and .NET Core 2.0 - Copy failed
问题描述
在学习几个 .NET Core 2.0 Visual Studio Team Services 持续集成/持续交付示例时,我在 VSTS 中遇到了复制错误.
While following a couple .NET Core 2.0 Visual Studio Team Services Continuous Integration/Continuous Delivery examples I bumped into a copy error in VSTS.
通过 VS17 添加 docker 支持在本地使用这样的 dockerfile 效果很好.
Adding docker support via VS17 works great locally with a dockerfile like this.
FROM microsoft/aspnetcore:2.0
ARG source
WORKDIR /app
EXPOSE 80
COPY ${source:-obj/Docker/publish} .
ENTRYPOINT ["dotnet", "myapp.dll"]
通过一个 MVC 应用程序和一个 WebAPI 应用程序,它在本地与 docker-compose 一起工作得很好.
With an MVC app and a WebAPI app it worked well with docker-compose locally.
在添加 VSTS CI 构建过程并运行它时,我不断遇到副本错误.
When adding a VSTS CI build process and running it I kept hitting errors with the copy.
构建 myapp 服务myapp"失败构建:复制失败:GetFileAttributesEx?C:WindowsTEMPdocker-builder91objDockerpublish:系统找不到指定的路径.C:程序FilesDockerdocker-compose.exe 失败并返回代码:1
Building myapp Service 'myapp' failed to build: COPY failed: GetFileAttributesEx ?C:WindowsTEMPdocker-builder91objDockerpublish: The system cannot find the path specified. C:Program FilesDockerdocker-compose.exe failed with return code: 1
推荐答案
我发现的解决方法是 来自本博客.
请注意,他们在 linux docker 机器上遇到了错误
Note that they hit an error on a linux docker machine
复制失败:stat/var/lib/docker/tmp/docker-builder613328056/obj/Docker/publish: 没有那个文件或目录/usr/bin/docker 失败并返回代码:1
COPY failed: stat /var/lib/docker/tmp/docker-builder613328056/obj/Docker/publish: no such file or directory /usr/bin/docker failed with return code: 1
解决方案:
像这样制作一个 Dockerfile.ci
Make a Dockerfile.ci like this
FROM microsoft/aspnetcore-build:2.0 AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out
# Build runtime image
FROM microsoft/aspnetcore:2.0
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "SiliconValve.Vsts.DockerDemo.dll"]
它还需要修改 .dockerignore 文件.
It also requires modifying the .dockerignore file.
bin/
obj/
!*.dll
!obj/Docker/publish/*
!obj/Docker/empty/
这允许我继续 CI 过程,但是我认为有一个更容易解决问题的方法.
This allows me to continue the CI process, however I assume there's an easier fix to the problem.
这篇关于带有 docker 和 .NET Core 2.0 的 VSTS CI/CD - 复制失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!