问题描述
.Net Core (3.1) 使用 Docker(Linux 容器)的 Web API.
.Net Core (3.1) Web API using Docker (Linux container).
我通过 nuget 包 IBM.Data.DB2.Core-lnx (3.1.0.300) 建立了 Db2 连接.
I have a Db2 connection via nuget package IBM.Data.DB2.Core-lnx (3.1.0.300).
当我独立于 VisualStudio 2019 构建和运行 Dockerfile 时,此 Db2 连接工作正常.
This Db2 connection works fine when I build and run my Dockerfile independently of VisualStudio 2019.
但是,当尝试通过 VS(快速模式)进行调试时,我遇到了这个异常:
However, when attempting to debug via VS (fast mode), I run into this exception:
无法加载共享库libdb2.so"或其依赖项之一.为了帮助诊断加载问题,请考虑设置 LD_DEBUG 环境变量:liblibdb2.so: cannot open shared object file: No such file or directory
我的猜测是找不到资源是因为快速模式调试与 Docker 容器一起工作的方式.将应用程序输出复制到挂载后,我的 IBM ENV 变量无法找到 NuGet clidriver 文件夹.这些通常如下所示:
My guess is this failure to locate resources is because of the way fast mode debugging works with Docker containers. With the app output copied to a mount, my IBM ENV variables aren't able to find the NuGet clidriver folder. These typically look like this:
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:/app/clidriver/adm"
如何更新这些以指向已安装的应用内容?假设这是问题......
How can I update these to point to the mounted app contents? Assuming that is the problem...
*请注意,我正在我的 Dockerfile 的基础中安装包 libxml2-dev.
*Note that I am installing package libxml2-dev in the base of my Dockerfile.
如果有人在 Linux 容器中调试 Db2 连接的成功策略,我很想听听你做了什么.非常感谢.
If anyone has a successful strategy for debugging Db2 connections in a Linux container, I would love to hear what you've done. Much thanks in advance.
推荐答案
在调试容器上运行 shell 可以让我看到挂载的内容并获取 clidriver 路径.在 Db2 环境变量中设置此项可解决问题:
Running a shell on the debugging container allowed me to see the mounted contents and get the clidriver path. Setting this in the Db2 environment variables fixed the issue:
ENV DB2_CLI_DRIVER_INSTALL_PATH="/app/bin/Debug/netcoreapp3.1/clidriver"
LD_LIBRARY_PATH="/app/bin/Debug/netcoreapp3.1/clidriver/lib"
LIBPATH="/app/bin/Debug/netcoreapp3.1/clidriver/lib"
PATH=$PATH:"/app/bin/Debug/netcoreapp3.1/clidriver/bin:/app/bin/Debug/netcoreapp3.1/clidriver/lib:/app/bin/Debug/netcoreapp3.1/clidriver/adm"
这篇关于.Net Core Linux - Docker - 使用 DB2 进行本地调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!