c# - 如何为 .NET 解决方案构建具有多个依赖项的 Docker 镜像?

标签 c# docker dockerfile azure-iot-edge

它可能有点长,但我认为它很容易阅读......所以让我们开始......

我有一个使用 IoT Edge Tools 创建的 IoT-Edge 解决方案.
它会生成一个 Dockerfile,它适用于没有外部 DLL 作为依赖项的项目。

当我在此模块( MySqlAdapter )中添加多个 DLL( BaseAdapterHelperMyEdgeModule )时,问题就出现了,而在尝试构建镜像时没有更改 Dockerfile,

它抛出一个错误:

Skipping project "/MySqlAdapter/MySqlAdapter.csproj" because it was not found. Skipping project "/MySqlAdapter/MySqlAdapter.csproj" because it was not found.



...

... : warning : The referenced project '../MySqlAdapter/MySqlAdapter.csproj' does not exist. [/app/MyEdgeModule.csproj]



这是为 MyEdgeModule 生成的 Dockerfile
FROM microsoft/dotnet:2.1-sdk AS build-env
WORKDIR /app

COPY *.csproj ./
RUN dotnet restore

COPY *.csproj ./
RUN dotnet restore

COPY . ./
RUN dotnet publish -c Release -o out

FROM microsoft/dotnet:2.1-runtime-stretch-slim
WORKDIR /app
COPY --from=build-env /app/out ./

RUN useradd -ms /bin/bash moduleuser
USER moduleuser

ENTRYPOINT ["dotnet", "MyEdgeModule.dll"]

这些类库项目位于 Dockerfile 中的“../{projname}/*.csproj”。

因此,我尝试将这些项目单独添加到 Dockerfile 中,以查看是否可以正常工作,但没有成功。

我什至从 documentation据说:

The path must be inside the context of the build; you cannot COPY ../something /something, because the first step of a docker build is to send the context directory (and subdirectories) to the docker daemon.



据我了解我的context是我尝试返回的文件夹,以查找我的依赖项目,这似乎是不可能的。

假设它有几十个外部 DLL 作为依赖项,我如何为这个项目创建一个图像?

最佳答案

目前可行的方法是创建一个新的 .NET Core 项目并使用 Add Docker Support ,每次生成它时,它都会使用引用中的所有依赖项刷新 Dockerfile。

为了工作 Dockerfile 需要移动到解决方案目录,而不是在生成它的项目文件夹中。

关于c# - 如何为 .NET 解决方案构建具有多个依赖项的 Docker 镜像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52820912/

相关文章:

docker - 无法访问Docker容器中的Spring Boot API

c# - 锁定跨多个线程使用的对象中的关键部分

c# - SQL 让我头疼 - 多个连接

c# - 检查当前请求是否来自 httpmodule 中的 mvc 页面

docker - 我如何与Docker一起执行Gobblin

docker - GET to API可在浏览器中使用,但不适用于Postman

docker - Gitlab CI 服务端口是如何公开的?

docker - 使用容器编排处理 EF Core 迁移

bash - 如何防止退出/bin/bash session 后停止Docker的容器

c# - 从 Net Core 3.1 迁移到 Net 6 期间,以下方法或属性之间的调用不明确