它可能有点长,但我认为它很容易阅读......所以让我们开始......
我有一个使用 IoT Edge Tools 创建的 IoT-Edge 解决方案.
它会生成一个 Dockerfile,它适用于没有外部 DLL 作为依赖项的项目。
当我在此模块( MySqlAdapter
)中添加多个 DLL( BaseAdapter
、 Helper
、 MyEdgeModule
)时,问题就出现了,而在尝试构建镜像时没有更改 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
生成的 DockerfileFROM 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/