在Docker中与.net核心建立DB2连接时无法加载DLL'libdb2.so' [英] Unable to load DLL 'libdb2.so' when establishing a DB2 connection with .net core in docker

查看:135
本文介绍了在Docker中与.net核心建立DB2连接时无法加载DLL'libdb2.so'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使libdb2.so文件对DB2软件包可见?我已验证该软件包可在Ubuntu中运行,但无法使其在Docker中运行.

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

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

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

未处理的异常:System.DllNotFoundException:无法加载DLL'libdb2.so':找不到指定的模块.

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

如您所见,LD_LIBRARY_PATH环境变量按照文档在

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

确实可以打印

/app/db2Lib

/app/db2Lib

推荐答案

有关将来的参考,请参见

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

这篇关于在Docker中与.net核心建立DB2连接时无法加载DLL'libdb2.so'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆