具有多个 cs 项目引用的 dotnetcore2.0 的 DockerFile
DockerFile for dotnetcore2.0 with multiple cs project references
我是 运行 一个 .netcore2.0 webapi,使用 Visual studio 2017 for MAC。
我的项目结构如下。
src
--Solution.sln
-- Common
-- commonPrj
-- Common.csproj
--Data
-- QM
-- QM.csproj
--Repo
--Repo.csproj
--Ser
-- Host
-- Api
--api.csproj
我也有 DOCKERFILE 内容。在执行 dotnet 构建过程时抛出错误,因为构建代理无法解析 common.csproj/ 我认为我的 docker 文件定义是错误的。有人可以协助完成这项工作[我在这里尝试了很多选项 dockerfile]>?
#FROM microsoft/aspnetcore-build:2.0 AS build-env
FROM microsoft/aspnetcore
# copy csproj and restore as distinct layers
#COPY *.csproj ./
#RUN dotnet restore
# copy everything else and build
#COPY . ./ ./ ./
#RUN dotnet restore
#RUN dotnet publish -c Release -o out
# build runtime image
#FROM microsoft/aspnetcore:2.0
#WORKDIR /app
#COPY --from=build-env /app/out .
#EXPOSE 5000
COPY ./out /out
WORKDIR /out
#WORKDIR /publish
ENTRYPOINT ["dotnet", "Rando.MortgageCenter.WebAPI.dll"]
我正在尝试使用 Docker 云环境 [cloud.docker.com/swarm]
构建此 docker 图像
Error Log from docker cloud build
Building in Docker Cloud's infrastructure...
Cloning into '.'...
Warning: Permanently added the RSA host key for IP address '104.192.143.1' to the list of known hosts.
Reset branch 'master'
Your branch is up-to-date with 'origin/master'.
KernelVersion: 4.4.0-93-generic
Arch: amd64
BuildTime: 2017-08-17T22:50:04.828747906+00:00
ApiVersion: 1.30
Version: 17.06.1-ce
MinAPIVersion: 1.12
GitCommit: 874a737
Os: linux
GoVersion: go1.8.3
Starting build of index.docker.io/systreeau/mortgagecenter:latest...
Step 1/4 : FROM microsoft/aspnetcore
---> f79840764591
Step 2/4 : COPY ./out /out
COPY failed: stat /var/lib/docker/tmp/docker-builder177013174/out: no such file or directory
ERROR: Build failed: COPY failed: stat /var/lib/docker/tmp/docker-builder177013174/out: no such file or directory
ERROR: Build failed with exit code 2
所以我发现您必须将 DOCKERFILE 放在 src 文件夹中,该文件夹是解决方案的根目录。这样 docker 上下文就变成了这个路径。
现在你有一个 Dockerfile 如下
FROM microsoft/aspnetcore-build:2.0 as build
WORKDIR /app
COPY . .
#COPY Solution.sln .
# RUN ls -l
RUN dotnet restore ./Solution.sln
COPY . .
RUN dotnet publish ./Ser/Host/Api/api.csproj --output /out/ --configuration Release
# runtime image
FROM microsoft/aspnetcore:2.0
WORKDIR /app
COPY --from=build /out .
ENTRYPOINT ["api.dll"]
希望这对遇到我所面临问题的人有所帮助
我是 运行 一个 .netcore2.0 webapi,使用 Visual studio 2017 for MAC。 我的项目结构如下。
src
--Solution.sln
-- Common
-- commonPrj
-- Common.csproj
--Data
-- QM
-- QM.csproj
--Repo
--Repo.csproj
--Ser
-- Host
-- Api
--api.csproj
我也有 DOCKERFILE 内容。在执行 dotnet 构建过程时抛出错误,因为构建代理无法解析 common.csproj/ 我认为我的 docker 文件定义是错误的。有人可以协助完成这项工作[我在这里尝试了很多选项 dockerfile]>?
#FROM microsoft/aspnetcore-build:2.0 AS build-env
FROM microsoft/aspnetcore
# copy csproj and restore as distinct layers
#COPY *.csproj ./
#RUN dotnet restore
# copy everything else and build
#COPY . ./ ./ ./
#RUN dotnet restore
#RUN dotnet publish -c Release -o out
# build runtime image
#FROM microsoft/aspnetcore:2.0
#WORKDIR /app
#COPY --from=build-env /app/out .
#EXPOSE 5000
COPY ./out /out
WORKDIR /out
#WORKDIR /publish
ENTRYPOINT ["dotnet", "Rando.MortgageCenter.WebAPI.dll"]
我正在尝试使用 Docker 云环境 [cloud.docker.com/swarm]
构建此 docker 图像Error Log from docker cloud build
Building in Docker Cloud's infrastructure...
Cloning into '.'...
Warning: Permanently added the RSA host key for IP address '104.192.143.1' to the list of known hosts.
Reset branch 'master'
Your branch is up-to-date with 'origin/master'.
KernelVersion: 4.4.0-93-generic
Arch: amd64
BuildTime: 2017-08-17T22:50:04.828747906+00:00
ApiVersion: 1.30
Version: 17.06.1-ce
MinAPIVersion: 1.12
GitCommit: 874a737
Os: linux
GoVersion: go1.8.3
Starting build of index.docker.io/systreeau/mortgagecenter:latest...
Step 1/4 : FROM microsoft/aspnetcore
---> f79840764591
Step 2/4 : COPY ./out /out
COPY failed: stat /var/lib/docker/tmp/docker-builder177013174/out: no such file or directory
ERROR: Build failed: COPY failed: stat /var/lib/docker/tmp/docker-builder177013174/out: no such file or directory
ERROR: Build failed with exit code 2
所以我发现您必须将 DOCKERFILE 放在 src 文件夹中,该文件夹是解决方案的根目录。这样 docker 上下文就变成了这个路径。
现在你有一个 Dockerfile 如下
FROM microsoft/aspnetcore-build:2.0 as build
WORKDIR /app
COPY . .
#COPY Solution.sln .
# RUN ls -l
RUN dotnet restore ./Solution.sln
COPY . .
RUN dotnet publish ./Ser/Host/Api/api.csproj --output /out/ --configuration Release
# runtime image
FROM microsoft/aspnetcore:2.0
WORKDIR /app
COPY --from=build /out .
ENTRYPOINT ["api.dll"]
希望这对遇到我所面临问题的人有所帮助