1

I have few microservices (each docker file at project level) and they all consume "commonDLL" project. The commondll project is referenced in each micro services solution file. Running into issues with generating docker images. It says unable to find the external project while copying. How should the docker file be defined? Do I need a Docker Compose file? Some say to create a image just for commondll project, how would i reference in each microservices docker file?

I have limited knowledge of "Docker". Eventually, it will be deployed into AKS. Any help is appreciated.

Project Structure (Image)

Project Structure

Docker file

    #See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app


FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ["CompanyName.AccountService/CompanyName.AccountService.csproj", "CompanyName.AccountService/"]
COPY ["../CompanyName.CoreProject/CoreProject/CoreProject.csproj", "../CompanyName.CoreProject/CoreProject/"] (********FAILED******)
RUN dotnet restore "CompanyName.AccountService/CompanyName.AccountService.csproj"
COPY . .
RUN dotnet publish "CompanyName.AccountService.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /appc
COPY --from=build /app/publish .

EXPOSE 500
EXPOSE 5000
ENV ASPNETCORE_URLS http://*:500;https://*:5000;
ENTRYPOINT ["dotnet", "CompanyName.AccountService.dll"]
Sunny B
  • 11
  • 3
  • What does your current Dockerfile look like, and what error are you getting? Does [How to include files outside of Docker's build context?](https://stackoverflow.com/questions/27068596/how-to-include-files-outside-of-dockers-build-context) answer your question? – David Maze May 30 '21 at 11:11
  • Please see the docker file (updated post). Its unable to find external (core project dll's) from the docker file. – Sunny B May 30 '21 at 13:53
  • You can't `COPY ../anything`; you need to change the build context to a higher-level directory, and then `COPY` from subdirectories of that. The question I linked to has further details. – David Maze May 30 '21 at 14:03

1 Answers1

0

Due to the fact you did not publish your docker file I could guess what you are doing.

You may have a Dockerfile like this:

FROM someimage

ADD /my-bin-folder/my-dependency.dll
# and so on...

Then you issue the command docker build ., where . is the so named docker build path, so keep in mind the all the ADD and COPY instruction are **relative to the context path`, you absolutely cannot reference resources outside of it.

Solution: copy resources to add inside you context path, build the docker image referencing local context path resources, remotve temporary dependencies.

Build script

cp /my-bin-folder/my-dependency.dll .
docker build .
rm /my-bin-folder/my-dependency.dll

Dockerfile

FROM someimage

ADD my-dependency.dll
# and so on...

Antonio Petricca
  • 8,891
  • 5
  • 36
  • 74