4

How do I make the libdb2.so file visible to the DB2 package? I have verified that the package works in Ubuntu, but I cannot make it work inside Docker.

Dockerfile

FROM microsoft/aspnetcore:1.0
#assume the built app is in /app from the build so that the entrypoint command runs in the correct path
WORKDIR /app

#need to specify db2 driver lib
ENV LD_LIBRARY_PATH="/app/db2Lib"

#move all the source code in local directory ./app into the container directory /app
COPY ./app .

RUN mkdir -p db2Lib

ADD db2Lib db2Lib/
ADD ./runImage.sh .


RUN chmod -R a+wrx runImage.sh

EXPOSE 8080
ENTRYPOINT ["./runImage.sh"]

runImage.sh

#!/bin/bash
ls $LD_LIBRARY_PATH
echo $LD_LIBRARY_PATH
dotnet app.dll

Upon running the image, I get the following prints in the console

#from ls $LD_LIBRARY_PATH
icc 
libDB2xml4c.so
libDB2xml4c.so.58
libDB2xml4c.so.58.0
libdb2.so
libdb2.so.1
libdb2clixml4c.so
libdb2clixml4c.so.1
libdb2o.so
libdb2o.so.1
#from echo $LD_LIBRARY_PATH
/app/db2Lib

but when my application runs, I get the following error

Unhandled Exception: System.DllNotFoundException: Unable to load DLL 'libdb2.so': The specified module could not be found.

As you can see, the LD_LIBRARY_PATH environment variable properly points to the correct directory as the documentation instructs at https://www.ibm.com/developerworks/community/blogs/96960515-2ea1-4391-8170-b0515d08e4da/entry/Instructions_for_downloading_and_using_DB2_NET_Core_provider_package?lang=en.

To double check that the environment variable is being set, I do

Console.WriteLine(Configuration["LD_LIBRARY_PATH"]);

which indeed prints

/app/db2Lib

Simon
  • 1,681
  • 1
  • 21
  • 34
  • Do you use nuget packages for install db2 drivers? – Roman Patutin Dec 05 '17 at 16:04
  • May be check file permissions? – mustaccio Dec 06 '17 at 00:14
  • As I understand for linux you need to use other nuget package: https://www.nuget.org/packages/IBM.EntityFrameworkCore-lnx (with -lnx postfix). And you can copy so from nuget package path $HOME/.nuget/packages/IBM.Data.DB2.Core-lnx//build/clidriver/lib – Roman Patutin Dec 06 '17 at 10:04
  • @mustaccio good suggestion. unfortunately i tried adding chmod -R a+wrx db2Lib and it still doesn't work. ls -l $LD_LIBRARY_PATH confirmed its files had -rwxrwxrwx – Simon Dec 06 '17 at 15:03
  • apologies. i am using https://www.nuget.org/packages/IBM.EntityFrameworkCore-lnx/1.1.1.101 – Simon Dec 06 '17 at 17:06
  • @Simon Any luck? I am facing this today. My setup is similar to yours, same error. I also have the LD_LIBRARY_PATH set correctly. – Botonomous Dec 07 '17 at 19:27
  • @Botonomous it's an internal problem. the ibm team is working on a solution. see https://www.ibm.com/developerworks/community/forums/html/topic?id=80fcd246-baed-418a-8590-a1b1e52fab98&ps=100&tags=&query=&filter=&sortBy=&order=asc "We are looking into this issue and will update you once we have a working solution. Obviously, in Docker environment the values of LD_LIBRARY_PATH is not being picked up by the application." – Simon Dec 07 '17 at 22:21
  • @Simon Thanks for the reply. Hope they get to the fix soon. I am going to try some poking around and will report back here if I get out fixed. Please do the same if you get yours working. – Botonomous Dec 07 '17 at 23:17
  • @Botonomous as a work around, we had to spin a node server for db2 connection and use it as an internal api – Simon Dec 08 '17 at 02:58
  • 1
    Anyone ever get this working? – Botonomous Oct 09 '18 at 17:12

4 Answers4

3

For any future reference here is the blog which explains what is needed to make it work on Docker. The example is related to Console Application but should hold good for other types of applications also. In summary, you need to have libxml2.so.2.7.6 in the system. If not, it can be downloaded and kept in the lib folder. This libxml2.so.2 needs to be linked to libdb2.so

    ln <libpath>/libxml2.so.2.7.6 <libpath>/libxml2.so.2

In the application's DockerFile, these two entries should be there before the entry point
    ENV LD_LIBRARY_PATH="<libpath>"
    Env PATH=$PATH:"<libpath>/bin:<libpath>/lib"
    ENTRYPOINT ["dotnet", "ConsoleApp1.dll"]
Vishwa
  • 31
  • 4
  • 2
    A link to a solution is welcome, but please ensure your answer is useful without it: [add context around the link](//meta.stackexchange.com/a/8259) so your fellow users will have some idea what it is and why it’s there, then quote the most relevant part of the page you're linking to in case the target page is unavailable. [Answers that are little more than a link may be deleted.](//stackoverflow.com/help/deleted-answers) – 4b0 May 22 '18 at 04:06
1

For the latest version 3.1.0.400 I found out that the required LD_LIBRARY_PATH is located in /app/clidriver/lib by executing the following in my Dockerfile:

RUN find / -name clidriver -type d

So I just installed the libxml2 package

RUN apt-get update \
    && apt-get install -y libxml2-dev

and set the library path

ENV LD_LIBRARY_PATH=/app/clidriver/lib

It's also important to include the right packages in the csproj file depending on the environment! The OS variable is usefull here, so it will work on both Win/Linux systems:

<PackageReference Include="IBM.Data.DB2.Core" Version="3.1.0.400" Condition="'$(OS)' == 'WINDOWS_NT'"/>
<PackageReference Include="IBM.Data.DB2.Core-lnx" Version="3.1.0.400" Condition="'$(OS)' == 'UNIX'"/>
Lion
  • 16,606
  • 23
  • 86
  • 148
0

As pointed out by @vishwa, the libdb2.so needs libxml2.so. My Dockerfile looks like this:

FROM microsoft/dotnet:2.1-sdk

ENV APP_DIR=/app \
    LD_LIBRARY_PATH=/app/bin/clidriver/lib:/app/bin/clidriver/lib/libdb2.so \
    PATH=${PATH}:/app/clidriver/bin:/app/clidriver/lib

RUN set -e; \
    mkdir -p ${APP_DIR}; \
    apt-get update; \
    apt-get install -y libxml2-dev;

WORKDIR ${APP_DIR}

COPY Pastdev.Example.App Pastdev.Example.App

RUN set -e; \
    dotnet build .; \
    dotnet publish --no-restore --no-build \
        -o ${APP_DIR}/bin \
        Pastdev.Example.App/Pastdev.Example.App.csproj

ENTRYPOINT ["dotnet", "/app/bin/Pastdev.Example.App.dll"]

I also wanted to be able to build and run on windows outside of docker so I set up my .csproj like this:

  <ItemGroup Condition="'$(os)' == 'UNIX'">
    <PackageReference Include="IBM.Data.DB2.Core-lnx" Version="1.2.2.100" />
  </ItemGroup>

  <ItemGroup Condition="'$(os)' == 'Windows_NT'">
    <PackageReference Include="IBM.Data.DB2.Core" Version="1.2.2.100" />
  </ItemGroup>
Lucas
  • 14,227
  • 9
  • 74
  • 124
0

I could fix my project updating the following env variables:

ENV DB2_CLI_DRIVER_INSTALL_PATH="/app/clidriver" \
    LD_LIBRARY_PATH="/app/clidriver/lib" \
    LIBPATH="/app/clidriver/lib" \
    PATH=$PATH:"/app/clidriver/bin:/app/clidriver/lib"

and also installing this library libxml2:

RUN apt-get -y update && apt-get install -y libxml2

I've pushed my project to the following repo:

https://github.com/renatomatos79/docker-netcore-db2-client-api/blob/main/Dockerfile