【问题标题】:Issue with node-oracledb inside a Docker containerDocker 容器内的 node-oracledb 问题
【发布时间】:2020-10-05 14:36:35
【问题描述】:

我有一个 Nest.js 应用程序,它通过 TypeORM 连接到 Oracle 数据库,我正在尝试使用 Docker 将我的应用程序容器化。所以这里的问题是,当应用程序没有被容器化时,它可以正常工作,但是当我这样做时,我会收到以下错误。

[Nest] 19   - 06/16/2020, 4:00:52 AM   [TypeOrmModule] Unable to connect to the database. Retrying (4)... +3003ms
 Error: DPI-1047: Cannot locate a 64-bit Oracle Client library: "libclntsh.so: cannot open shared object file: No such file or directory". See https://oracle.github.io/odpi/doc/installation.html#linux for help
Node-oracledb installation instructions: https://oracle.github.io/node-oracledb/INSTALL.html
You must have 64-bit Oracle client libraries in LD_LIBRARY_PATH, or configured with ldconfig.
If you do not have Oracle Database on this computer, then install the Instant Client Basic or Basic Light package from
http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html
    at OracleDb.createPool (/app/node_modules/oracledb/lib/oracledb.js:202:8)
    at OracleDb.createPool (/app/node_modules/oracledb/lib/util.js:185:19)

我确保在我的 Dockerfile 中添加 Oracle 瘦客户端所需的依赖项,如下所示

FROM oraclelinux:7-slim
RUN  yum -y install oracle-release-el7 oracle-nodejs-release-el7 && \
   yum-config-manager --disable ol7_developer_EPEL --enable ol7_oracle_instantclient && \
   yum -y install oracle-instantclient19.5-basiclite && \
   rm -rf /var/cache/yum

FROM node:10
WORKDIR /app
COPY ./package.json ./

我不确定要在此处添加什么其他内容才能使这项工作正常进行。我从这里https://oracle.github.io/node-oracledb/INSTALL.html#docker 得到了一些关于为 oracle 客户端添加什么的说明

【问题讨论】:

  • LD_LIBRARY_PATH 不应该是 Instant Client 19 RPM 所必需的,因为它在软件包安装期间运行 ldconfig
  • 一个简单的示例应用程序有效吗?如果没有,请分享一些我们可以测试的东西。也许打开一个 GitHub 问题来做到这一点。

标签: node.js oracle docker nestjs node-oracledb


【解决方案1】:

您似乎正在尝试使用多阶段构建。我在我的博文Docker for Oracle Database Applications in Node.js and Python 的“Node.js Dockerfile 示例 3”中讨论了这个问题。

你可以试试这样的:

FROM oraclelinux:7-slim as builder

ARG release=19
ARG update=5

RUN yum -y install oracle-release-el7 &&
     oracle-instantclient${release}.${update}-basiclite

RUN rm -rf /usr/lib/oracle/${release}.${update}/client64/bin
WORKDIR /usr/lib/oracle/${release}.${update}/client64/lib/
RUN rm -rf *jdbc* *occi* *mysql* *jar

# Get a new image
FROM node:12-buster-slim

# Copy the Instant Client libraries, licenses and config file from the previous image
COPY --from=builder /usr/lib/oracle /usr/lib/oracle
COPY --from=builder /usr/share/oracle /usr/share/oracle
COPY --from=builder /etc/ld.so.conf.d/oracle-instantclient.conf /etc/ld.so.conf.d/oracle-instantclient.conf

RUN apt-get update && apt-get -y upgrade && apt-get -y dist-upgrade && apt-get install -y libaio1 && \
    apt-get -y autoremove && apt-get -y clean && \
    ldconfig

总的来说,这可能不值得这么复杂。查看博客文章中的另一个示例。或者使用Oracle的Dockerfile:https://github.com/oracle/docker-images/tree/master/OracleLinuxDevelopers/oraclelinux7/nodejs/12-oracledb

【讨论】:

    猜你喜欢
    • 2020-09-06
    • 2019-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-16
    • 1970-01-01
    相关资源
    最近更新 更多