Topic
  • 5 replies
  • Latest Post - ‏2019-06-14T09:02:21Z by mark.austin42
mark.austin42
mark.austin42
4 Posts

Pinned topic Connect to DB2 on an IBM I Series from dotnet core on a linux docker container

‏2019-06-11T08:09:17Z | db2 docker dotnet linux

Hello,

I am trying to connect to DB2 on an IBM I Series from dotnet core on a linux docker container.

My test application is a simple .NET Core 2.2 Console with the IBM.Data.DB2.Core-lnx 1.3.0.100 nuget package. It has the simple DB2Connection/DB2Command code to read a row from a table, which all works when debugging with the windows version of the package.

I've copied the trial license to the route of my project and added these settings just before the ENTRYPOINT in my dockerfile
COPY db2consv_t.lic /app/clidriver/license/
ENV LD_LIBRARY_PATH="/app/clidriver/lib/"
ENV PATH=$PATH:"/app/clidriver/bin:/app/clidriver/lib"

When I run the docker image I get this 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: Error loading shared library liblibdb2.so.so: No such file or directory"

I get this error on Debian 9 (2.2-stretch), Alpine 3.9 (2.2-alpine3.9) and Ubuntu 18.04 (2.2-bionic) Linux amd64 microsoft dotnet core images from http://hub.docker.com/_/microsoft-dotnet-core

When I run printenv in the container the settings look good to me

LD_LIBRARY_PATH=/app/clidriver/lib/
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/app/clidriver/bin:/app/clidriver/lib

The 'libdb2.so' file exists in the clidriver/lib folder and the license file is in the folder

I've set the LD_DEBUG environment variable to all and looked through the files, unfortunately I am not sure what I am looking for.

Can someone please help?

  • VishDev2018
    VishDev2018
    64 Posts

    Re: Connect to DB2 on an IBM I Series from dotnet core on a linux docker container

    ‏2019-06-11T09:20:50Z  

    Hi,

     you may want to refer to the blog here which explains the steps needed to make it work on a linux container

    https://www.ibm.com/developerworks/community/blogs/96960515-2ea1-4391-8170-b0515d08e4da/entry/Using_NET_Core?lang=en

     

    Thanks

    Vishwa

  • mark.austin42
    mark.austin42
    4 Posts

    Re: Connect to DB2 on an IBM I Series from dotnet core on a linux docker container

    ‏2019-06-11T13:16:59Z  

    Hi,

     you may want to refer to the blog here which explains the steps needed to make it work on a linux container

    https://www.ibm.com/developerworks/community/blogs/96960515-2ea1-4391-8170-b0515d08e4da/entry/Using_NET_Core?lang=en

     

    Thanks

    Vishwa

    Hi Vishwa,

    Thank you for your speedy response.

    I followed the supplied blog article for my original tests but with the latest versions of visual studio, .net, docker images and IBM.Data.DB2.Core-lnx package.

    The latest IBM.Data.DB2.Core-lnx package copies the clidriver, so I think that part of the document is redundant?

    Is the download and linking of libxml2.so.2 a required step for all images? Am I getting the "System.DllNotFoundException: Unable to load shared library 'libdb2.so' or one of its dependencies." exception because of libxml2.so.2? 

  • mark.austin42
    mark.austin42
    4 Posts

    Re: Connect to DB2 on an IBM I Series from dotnet core on a linux docker container

    ‏2019-06-11T13:17:32Z  

    Hi,

     you may want to refer to the blog here which explains the steps needed to make it work on a linux container

    https://www.ibm.com/developerworks/community/blogs/96960515-2ea1-4391-8170-b0515d08e4da/entry/Using_NET_Core?lang=en

     

    Thanks

    Vishwa

    Hi Vishwa,

    I have updated my dockerfile with these commands just before the entrypoint

    COPY db2consv_t.lic /app/clidriver/license/
    RUN echo 'http://dl-cdn.alpinelinux.org/alpine/v3.9/main/' >> /etc/apk/repositories
    RUN apk add 'libxml2==2.9.9-r1'
    RUN ln /usr/lib/libxml2.so.2.9.9 /app/clidriver/lib/libxml2.so.2
    ENV LD_LIBRARY_PATH="/app/clidriver/lib/"
    ENV PATH=$PATH:"/app/clidriver/bin:/app/clidriver/lib"

    My runtime image is from mcr.microsoft.com/dotnet/core/runtime:2.2-alpine3.9

    When I run my code in the container I still get the "System.DllNotFoundException: Unable to load shared library 'libdb2.so' or one of its dependencies." exception.

    These commands should cover all of the steps in the article.

    Please advise what step I have got wrong.

  • VishDev2018
    VishDev2018
    64 Posts

    Re: Connect to DB2 on an IBM I Series from dotnet core on a linux docker container

    ‏2019-06-13T10:21:49Z  

    Hi Vishwa,

    I have updated my dockerfile with these commands just before the entrypoint

    COPY db2consv_t.lic /app/clidriver/license/
    RUN echo 'http://dl-cdn.alpinelinux.org/alpine/v3.9/main/' >> /etc/apk/repositories
    RUN apk add 'libxml2==2.9.9-r1'
    RUN ln /usr/lib/libxml2.so.2.9.9 /app/clidriver/lib/libxml2.so.2
    ENV LD_LIBRARY_PATH="/app/clidriver/lib/"
    ENV PATH=$PATH:"/app/clidriver/bin:/app/clidriver/lib"

    My runtime image is from mcr.microsoft.com/dotnet/core/runtime:2.2-alpine3.9

    When I run my code in the container I still get the "System.DllNotFoundException: Unable to load shared library 'libdb2.so' or one of its dependencies." exception.

    These commands should cover all of the steps in the article.

    Please advise what step I have got wrong.

    Hi,

     it may take some time for me to validate the steps you have mentioned. Meanwhile, please try following the exact steps mentioned in the blog to check if that works.

     

    Regards

    Vishwa

     

  • mark.austin42
    mark.austin42
    4 Posts

    Re: Connect to DB2 on an IBM I Series from dotnet core on a linux docker container

    ‏2019-06-14T09:02:21Z  

    Hi,

     it may take some time for me to validate the steps you have mentioned. Meanwhile, please try following the exact steps mentioned in the blog to check if that works.

     

    Regards

    Vishwa

     

    Hi Vishwa,

    The IBM.Data.DB2.Core-lnx 1.3.0.100 nuget package doesn't seem to work with mcr.microsoft.com/dotnet/core/runtime:2.2-alpine3.9 if you change the distro to mcr.microsoft.com/dotnet/core/runtime:2.2-stretch-slim and use these commands in your docker file the connection works

    COPY db2consv_t.lic /app/clidriver/license/

    # Debian 9 (Stretch) - IBM Dependency fix
    RUN apt-get update
    RUN apt-get install -y libxml2

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

    Please can you let me know what commands I need to run for Alpine?

    Kind regards,
    Mark