1

We are working on deploying asp .net core api in google cloud run serverless container, as our api has dependency with db2 drivers so we have made following changes in dockerfile, and to download DB2 Drivers Package we are using this version of nuget package reference - "Net5.IBM.Data.Db2-lnx" Version="5.0.0.500", but our API is throwing below mentioned error.

Unable to load shared library 'libdb2.so' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibdb2.so: cannot open shared object file: No such file or directory

Following is our docker file changes.

FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
RUN apt-get update -y && apt-get install jq dos2unix curl -y

WORKDIR /app
EXPOSE 80
EXPOSE 443

RUN chmod -R 777 /app
ENV DB2_CLI_DRIVER_INSTALL_PATH=/app/clidriver
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/app/clidriver/lib
ENV LIBPATH=/app/clidriver/lib
ENV PATH=$PATH:/app/clidriver/bin:/app/clidriver/lib

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build

WORKDIR /src
COPY ["SourceCode/SomeAPI.WebApi/SomeAPI.WebApi.csproj", "SourceCode/SomeAPI.WebApi/"]
RUN dotnet restore "SourceCode/SomeAPI.WebApi/SomeAPI.WebApi.csproj"
COPY . .
WORKDIR "/src/SourceCode/SomeAPI.WebApi"
RUN dotnet build "SomeAPI.WebApi.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "SomeAPI.WebApi.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "SomeAPI.WebApi.dll"]
  • [.Net Core Linux - Docker - Local debugging with DB2](https://stackoverflow.com/questions/64828258/net-core-linux-docker-local-debugging-with-db2) suggests the library might be in a different path; have you tried looking in the partially-built image to see if it exists, but somewhere other than `/app/clidriver`? – David Maze Dec 10 '22 at 11:43
  • thanks for replying, Yes i already checked that running same image in my local, clidriver is only in 1 path i.e. /app/clidriver – Small Engineer Dec 10 '22 at 16:56
  • Below command i run to find clidriver path PS C:\WINDOWS> docker exec -it 81c1b8219edc bash root@81c1b8219edc:/app# cd .. root@81c1b8219edc:/# find / -name clidriver /app/clidriver also i checked above link earlier as well that is for netcoreapp3.1 and we are using net5. – Small Engineer Dec 10 '22 at 17:03

1 Answers1

0

Your answer served me really well.

The only thing I changed besides this was:

  1. Instaling the Net5.IBM.Data.Db2-lnx NuGet package Link to NuGET page

  2. Changing the aspnet runtime to Debian mcr.microsoft.com/dotnet/aspnet:5.0.15-bullseye-slim-amd64

EDIT: You have to remove "IBM.EntityFrameworkCore" from your projects, and only include "IBM.EntityFrameworkCore-lnx". This will for for sure hinder your dev process, unless you manage to find a workaround for running IBM.EntityFrameworkCore locally on Windows. Hope this helps.