How to build a Docker image with multiple dependencies for .NET Solution?
Asked Answered
S

2

6

It could be kind of long, but I think it's easy to read... So let's begin ...

I have an IoT-Edge Solution created with IoT Edge Tools. It generates a Dockerfile which works nice for a project without external DLLs as dependencies.

The problem comes when I add multiple DLLs(MySqlAdapter, BaseAdapter, Helper) in this module (MyEdgeModule), without changing the Dockerfile when trying to build an image,

It throws an error:

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]

and here is the generated Dockerfile for the MyEdgeModule

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"]

These class library projects are located at "../{projname}/*.csproj" from the Dockerfile.

So I tried to relatively add these projects individually to the Dockerfile just to see if's gonna work but with no success.

I even got on this from the documentation that it's said:

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.

As far as I understand my context is the folder from which I try to go back, to find my Dependency Projects which seems impossible.

How can I create an image for this project, assuming that it has dozens of external DLLs as dependencies ?

Stonedeaf answered 15/10, 2018 at 16:20 Comment(0)
S
5

A Thing that works for now is creating a fresh .NET Core project and using the Add Docker Support, each time when you generate it, it will refresh it Dockerfile with all of the dependecies from the References.

In order to work Dockerfile needs to be moved to the solution directory, instead in the project folder where it's generated.

Stonedeaf answered 16/10, 2018 at 11:49 Comment(2)
...then you're making a docker image of the whole solution? That's ridiculous.Templia
@ErçinDedeoğlu I'm waiting for your suggestion 3 years already.Stonedeaf
I
0

Auto generated Dockerfile doesn't work at my situation.

COPY failed: stat /var/lib/docker/tmp/docker-builder471019165/src/server/MyWebService/MyWebService.csproj: no such file or directory
Isotherm answered 20/8, 2019 at 8:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.