我在Linux上使用MSSQL在Asp.Bet Core 2应用程序上工作。我想配置CI和CD到Azure。 我在Visual Studio Team Services中定义了docker-compose任务,但是我收到了一个错误。
libuvc
这是我的docker-compose:
2017-11-09T20:24:09.4725450Z ##[section]Starting: Create images
2017-11-09T20:24:09.4801610Z ==============================================================================
2017-11-09T20:24:09.4817660Z Task : Docker Compose
2017-11-09T20:24:09.4835680Z Description : Build, push or run multi-container Docker applications. Task can be used with Docker or Azure Container registry.
2017-11-09T20:24:09.4852370Z Version : 0.4.7
2017-11-09T20:24:09.4867100Z Author : Microsoft Corporation
2017-11-09T20:24:09.4881820Z Help : [More Information](https://go.microsoft.com/fwlink/?linkid=848006)
2017-11-09T20:24:09.4897520Z ==============================================================================
2017-11-09T20:24:10.5040990Z [command]/usr/local/bin/docker-compose -f /opt/vsts/work/1/s/docker-compose.yml -f /opt/vsts/work/1/s/docker-compose.ci.build.yml -f /home/vsts/agent/.docker-compose.1510259050468.yml -p Travelingowe build
2017-11-09T20:24:10.8628630Z db uses an image, skipping
2017-11-09T20:24:10.8646610Z Building api
2017-11-09T20:24:10.9373040Z Step 1/7 : FROM microsoft/aspnetcore:2.0
2017-11-09T20:24:12.0041790Z 2.0: Pulling from microsoft/aspnetcore
2017-11-09T20:25:03.6328690Z Digest: sha256:e36cb8d1edcd1bfd7aea0412349482a9c1a601089d76d1a294067f5f7f1098a9
2017-11-09T20:25:03.6497680Z Status: Downloaded newer image for microsoft/aspnetcore:2.0
2017-11-09T20:25:03.6524910Z ---> e0e49def2506
2017-11-09T20:25:03.6551560Z Step 2/7 : MAINTAINER Maciej Skuratowski <maciejskuratowski@gmail.com>
2017-11-09T20:25:03.7496070Z ---> Running in e7667861d293
2017-11-09T20:25:03.9222120Z ---> 24ba03484562
2017-11-09T20:25:03.9436840Z Removing intermediate container e7667861d293
2017-11-09T20:25:03.9458600Z Step 3/7 : ARG source
2017-11-09T20:25:04.0562980Z ---> Running in 7b57f9fc515f
2017-11-09T20:25:04.2292420Z ---> 4d07188edf18
2017-11-09T20:25:04.2503550Z Removing intermediate container 7b57f9fc515f
2017-11-09T20:25:04.2581270Z Step 4/7 : WORKDIR /app
2017-11-09T20:25:04.5347440Z ---> 4546b8dc771f
2017-11-09T20:25:04.5527690Z Removing intermediate container 0a595d10e668
2017-11-09T20:25:04.5558170Z Step 5/7 : EXPOSE 80
2017-11-09T20:25:04.6765650Z ---> Running in aa273cc9ca2c
2017-11-09T20:25:04.8330020Z ---> 6dd874db617e
2017-11-09T20:25:04.8619290Z Removing intermediate container aa273cc9ca2c
2017-11-09T20:25:04.8650100Z Step 6/7 : COPY ${source:-obj/Docker/publish} .
2017-11-09T20:25:04.8686070Z Service 'api' failed to build: COPY failed: stat /var/lib/docker/tmp/docker-builder211771018/obj/Docker/publish: no such file or directory
2017-11-09T20:25:04.9064960Z ##[error]db uses an image, skipping
2017-11-09T20:25:04.9127660Z ##[error]Building api
2017-11-09T20:25:04.9175860Z ##[error]Service 'api' failed to build: COPY failed: stat /var/lib/docker/tmp/docker-builder211771018/obj/Docker/publish: no such file or directory
2017-11-09T20:25:04.9258880Z ##[error]/usr/local/bin/docker-compose failed with return code: 1
2017-11-09T20:25:04.9325830Z ##[section]Finishing: Create images
和docker-compose.ci.build.yml文件:
version: '3'
services:
api:
image: api
container_name: api
build:
context: ./Api
dockerfile: Dockerfile
ports:
- "8000:80"
depends_on:
- db
db:
image: "microsoft/mssql-server-linux"
container_name: mssql
environment:
SA_PASSWORD: "testtest3030!"
ACCEPT_EULA: "Y"
MSSQL_PID: "Developer"
ports:
- "127.0.0.1:8001:1433"
你知道我做错了吗?
答案 0 :(得分:0)
FROM microsoft/aspnetcore:2.0
ARG source
WORKDIR /app
EXPOSE 80
COPY ${source:-obj/Docker/publish} .
ENTRYPOINT [ "dotnet","MyWeb.Api.dll" ]
如果docker找不到您在COPY命令中指定的路径,则会产生错误:
Service 'api' failed to build: COPY failed: stat /var/lib/docker/tmp/docker-builder211771018/obj/Docker/publish: no such file or directory
所以,基本上,你需要做的是修复你的构建版本路径(你需要确保在正确的文件夹中构建后的文件)。
此外,如果执行:
,则会出现问题docker-compose build
它没有构建解决方案。这就是DockerFile无法找到所需文件夹的原因。如果在docker-compose之前执行以下命令,它将起作用。
dotnet publish ./YourSolution.sln -c Release -o ./obj/Docker/publish
答案 1 :(得分:0)
关于错误,原因是没有obj / Docker / publish文件夹或文件。 (查看列昂尼德的回答)
docker-compose.ci.build.yml
文件用于构建项目,docker-compose.yml
文件用于运行项目,因此您需要通过带有Dokcer-compose任务的docker-compose.ci.build.yml
文件构建项目,然后使用带有Docker-compose任务的docker-compose.yml
文件构建/运行图像。
有一个关于docker-compose.ci.build.yml,docker-compose.yml和Dockerfile的帖子:Asp.net core with linux docker container
更新
请参阅以下步骤将项目部署到Azure:
**/docker-compose.ci.build.yml
;操作:Run a Docker Compose command
;命令:run ci-build
)$(System.DefaultWorkingDirectory)/[your project path]/obj/Docker/publish
;内容:**
;目标文件夹:$(Build.ArtifactStagingDirectory)
)$(Build.ArtifactStagingDirectory)
)$(System.DefaultWorkingDirectory)/[artifact build definition name]/[artifact name]
;取消选中Publish using Web Deploy option
)