从多项目点网核心解决方案构建Docker映像 [英] Building a Docker image from a multi project dot net core solution
问题描述
我正在尝试从包含两个项目的Visual Studio解决方案构建docker映像:
- 一个项目包含通用代码( http方法,日志记录等)
- 另一个是业务逻辑和应用程序
我可以在Visual Studio中构建并运行,它会生成一个Docker映像,我可以将该映像部署到我们的测试环境中。但是,在测试环境中发送到API的所有POST都会返回500错误。我可以在错误响应中看到类似'/ Users / Tim / Documents / Dotnet Code / dotnetcore-app / App / MyClass.cs'
的引用,这使我怀疑
希望其他人也遇到类似的情况,或者可以为构建多项目提供一些指示。
免责声明:这是我第一次使用dotnet core和visual studio-我对docker有一定的经验。
如果您使用Visual Studio中的标准 Dockerfile模板,则可能会在本地PC上构建公共项目时遇到问题(可能是Windows)和在Docker容器中构建的主项目(可能是Linux)。 主 dll是指Windows内置的dll,因此存在问题。
请确保您不仅在复制主项目,而且在复制通用项目,以便dotnet可以
尝试以下dockerfile:
从microsoft / aspnetcore:2.0 AS基础
WORKDIR / app
ENV ASPNETCORE_ENVIRONMENT =生产
ENV ASPNETCORE_URLS http:// *:5000
EXPOSE 5000
从microsoft / aspnetcore-build:2.0 AS生成器
ARG配置=释放
WORKDIR / src
COPY * .sln ./
COPY Project.Main / Project.Main.csproj项目.Main /
COPY Project.Common / Project.Common.csproj Project.Common /
RUN dotnet restore
COPY。 。
WORKDIR / src / ProjectMain
RUN dotnet build -c $ Configuration -o / app
从builder AS发布
ARG Configuration =释放
RUN dotnet publish -c $ Configuration -o / app
从基础AS最终
WORKDIR / app
COPY --from = publish / app。
ENTRYPOINT [ dotnet, Project.Main.dll]
构建主项目,它在sln级别上执行。
I am trying to build a docker image from a visual studio solution that consists of two projects:
- one project contains common code (http methods, logging etc)
- the other is the business logic and application
I can build and run in Visual Studio, which produces a Docker image that I am able to deploy to our test environment. However, any POSTs sent to the API in the test environment return a 500 error. I can see references like: '/Users/Tim/Documents/Dotnet Code/dotnetcore-app/App/MyClass.cs'
in the error response, which leads me to suspect there is something up with the image - that path is on my laptop.
Hoping someone else may have come across something similar, or could provide some pointers about building a multi project solution like this into a Docker container.
Disclaimer: this is my first time working with dotnet core and visual studio - I have some experience with docker.
If you use "standard" Dockerfile template from Visual Studio, you might have issue with having your "common" project being built on your local PC (probably windows) and the "main" project being built in docker container (probably Linux). the "main" dll is referencing windows-built dll, hence the issues.
Make sure you are copying not only main project, but also the common project, so dotnet can build it in docker also.
Try out this dockerfile:
FROM microsoft/aspnetcore:2.0 AS base
WORKDIR /app
ENV ASPNETCORE_ENVIRONMENT=Production
ENV ASPNETCORE_URLS http://*:5000
EXPOSE 5000
FROM microsoft/aspnetcore-build:2.0 AS builder
ARG Configuration=Release
WORKDIR /src
COPY *.sln ./
COPY Project.Main/Project.Main.csproj Project.Main/
COPY Project.Common/Project.Common.csproj Project.Common/
RUN dotnet restore
COPY . .
WORKDIR /src/ProjectMain
RUN dotnet build -c $Configuration -o /app
FROM builder AS publish
ARG Configuration=Release
RUN dotnet publish -c $Configuration -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "Project.Main.dll"]
Although is to build the "Main" project, it's executed on the sln level.
这篇关于从多项目点网核心解决方案构建Docker映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!