本文是小编为大家收集整理的关于从一个多项目的dot net core解决方案中构建一个Docker镜像的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。
问题描述
我正在尝试从视觉工作室解决方案构建一个由两个项目组成的docker映像:
- 一个项目包含常见代码(HTTP方法,日志记录等)
- 另一个是业务逻辑和应用程序
我可以在Visual Studio中构建和运行,该录音室会产生我可以在我们的测试环境中部署的Docker映像.但是,在测试环境中发送到API的任何帖子都会返回500错误.我可以在错误响应中看到参考文献:'/Users/Tim/Documents/Dotnet Code/dotnetcore-app/App/MyClass.cs',这使我怀疑图像有一些东西 - 路径在我的笔记本电脑上.
希望其他人可能会遇到类似的东西,或者可以为建立这样的多项目解决方案提供一些指针.
免责声明:这是我第一次使用dotnet core和Visual Studio-我在Docker方面有一些经验.
推荐答案
如果您使用Visual Studio中的"标准" Dockerfile模板,则可能会出现在本地PC上构建"常见"项目(可能是Windows)(可能是Windows),并且在Docker Container中构建的" Main"项目(可能是Linux). "主要" DLL是引用Windows构建的DLL,因此问题.
确保您不仅要复制主要项目,还要复制通用项目,以便dotnet也可以在docker中构建.
尝试此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"]
尽管要构建"主要"项目,但它是在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.