Ziaf Nadeem
Ziaf Nadeem

Reputation: 11

How to setup oracle instant client in node alpine (docker)?

I am trying to setup oracle instant client in docker node alpine image. I have tried all the techniques mentioned in the oracle official blog plus the official website.

FROM node:14.17-alpine
WORKDIR /opt/oracle

RUN wget https://download.oracle.com/otn_software/linux/instantclient/instantclient-basiclite-linuxx64.zip && \
    unzip instantclient-basiclite-linuxx64.zip && \
    rm -f instantclient-basiclite-linuxx64.zip && \
    apk add libaio libnsl && \
    cd instantclient* && \
    rm -f *jdbc* *occi* *mysql* *jar uidrvci genezi adrci && \
    # echo /opt/oracle/instantclient* > /etc/ld.so.conf.d/oracle-instantclient.conf && \
    # ldconfig
# RUN wget https://download.oracle.com/otn_software/linux/instantclient/213000/instantclient-basic-linux.x64-21.3.0.0.0.zip
# #unzip instant client
# RUN unzip instantclient-basic-linux.x64-21.3.0.0.0.zip
# RUN rm instantclient-basic-linux.x64-21.3.0.0.0.zip
# RUN mv instantclient_21_3 /opt/oracle
# RUN apk add libaio libnsl
# ENV LD_LIBRARY_PATH=/opt/oracle/instantclient_21_3:$LD_LIBRARY_PATH
ENV LD_LIBRARY_PATH=/opt/oracle/${version}/client64/lib:$LD_LIBRARY_PATH


I have tried both approaches the ld_library_path plus the ld_config way, tried with multiple different versions of the instant client, none of them worked.

I get the following error

{

      "type": "Error",

      "message": "DPI-1047: Cannot locate a 64-bit Oracle Client library: \"Error loading shared library **libclntsh.so**: Exec format error\". See https://oracle.github.io/node-oracledb/INSTALL.html for help\nNode-oracledb installation instructions: https://oracle.github.io/node-oracledb/INSTALL.html\nYou must have 64-bit Oracle Client libraries configured with ldconfig, or in LD_LIBRARY_PATH.\nIf you do not have Oracle Database on this computer, then install the Instant Client Basic or Basic Light package from \nhttps://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html\n",

      "stack":

          Error: DPI-1047: Cannot locate a 64-bit Oracle Client library: "Error loading shared library libclntsh.so: Exec format error". See https://oracle.github.io/node-oracledb/INSTALL.html for help

          Node-oracledb installation instructions: https://oracle.github.io/node-oracledb/INSTALL.html

          You must have 64-bit Oracle Client libraries configured with ldconfig, or in LD_LIBRARY_PATH.

          If you do not have Oracle Database on this computer, then install the Instant Client Basic or Basic Light package from 

          https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html

          

              at OracleDb.getConnection (/usr/src/app/node_modules/oracledb/lib/oracledb.js:273:25)

              at OracleDb.getConnection (/usr/src/app/node_modules/oracledb/lib/util.js:178:19)

              at connectOracle (/usr/src/app/server/services/service1/dist/lib/index.js:20:70)

              at startServer (/usr/src/app/server/services/service1/dist/lib/index.js:46:57)

              at Object.<anonymous> (/usr/src/app/server/services/service1/dist/lib/index.js:75:5)

              at Module._compile (internal/modules/cjs/loader.js:1072:14)

              at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)

              at Module.load (internal/modules/cjs/loader.js:937:32)

              at Function.Module._load (internal/modules/cjs/loader.js:778:12)

              at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)

              at internal/main/run_main_module.js:17:47

      "errorNum": 0,

      "offset": 0

    }

Upvotes: 0

Views: 8510

Answers (3)

Shojib Flamon
Shojib Flamon

Reputation: 1529

This Dockerfile will make the node with oracle. But not the alpne

# Use Node.js base image
FROM node:18

# Set the working directory
WORKDIR /app

# Install Oracle Instant Client dependencies
RUN apt-get update && apt-get install -y libaio1 wget unzip

# Download and install Oracle Instant Client
RUN wget https://download.oracle.com/otn_software/linux/instantclient/instantclient-basiclite-linuxx64.zip && \
    unzip instantclient-basiclite-linuxx64.zip -d /opt/oracle && \
    rm instantclient-basiclite-linuxx64.zip && \
    ln -s /opt/oracle/instantclient_* /opt/oracle/instantclient

# Set library path
ENV LD_LIBRARY_PATH=/opt/oracle/instantclient

# Copy package.json and install dependencies
COPY package*.json ./

RUN npm install

# Copy the rest of the application code
COPY . .

# Expose the application port
EXPOSE 3000

# Command to run the application
CMD ["node", "index.js"]

Upvotes: 0

Richard Guo
Richard Guo

Reputation: 21

I'm using Oracle instantclient_19_22 and got the following error when starting the Docker container:

DPI-1047: Cannot locate a 64-bit Oracle Client library: "Error loading shared library libnsl.so.1: No such file or directory (needed by /opt/oracle/instantclient/libclntsh.so)".

I borrowed 3 lines from Ravil's answer. That fixed 3 missing shared library errors for me (libnsl.so.1, libresolv.so.2, and ld-linux-x86-64.so.2).

RUN ln -s /usr/lib/libnsl.so.3 /usr/lib/libnsl.so.1 && \
    ln -s /lib/libc.musl-x86_64.so.1 /usr/lib/libresolv.so.2 && \
    ln -s /lib/ld-musl-x86_64.so.1 /usr/lib/ld-linux-x86-64.so.2

I only need those 3 lines. Everything seems working fine.

Upvotes: 1

120m4n
120m4n

Reputation: 29

This works for me:

RUN apk --no-cache add libaio libnsl libc6-compat curl && \
    cd /tmp && \
    curl -o instantclient-basiclite.zip https://download.oracle.com/otn_software/linux/instantclient/instantclient-basiclite-linuxx64.zip -SL && \
    unzip instantclient-basiclite.zip && \
    mv instantclient*/ /usr/lib/instantclient && \
    rm instantclient-basiclite.zip && \
    ln -s /usr/lib/instantclient/libclntsh.so.19.1 /usr/lib/libclntsh.so && \
    ln -s /usr/lib/instantclient/libocci.so.19.1 /usr/lib/libocci.so && \
    ln -s /usr/lib/instantclient/libociicus.so /usr/lib/libociicus.so && \
    ln -s /usr/lib/instantclient/libnnz19.so /usr/lib/libnnz19.so && \
    ln -s /usr/lib/libnsl.so.2 /usr/lib/libnsl.so.1 && \
    ln -s /lib/libc.so.6 /usr/lib/libresolv.so.2 && \
    ln -s /lib64/ld-linux-x86-64.so.2 /usr/lib/ld-linux-x86-64.so.2

ENV ORACLE_BASE /usr/lib/instantclient
ENV LD_LIBRARY_PATH /usr/lib/instantclient
ENV TNS_ADMIN /usr/lib/instantclient
ENV ORACLE_HOME /usr/lib/instantclient
RUN apk add dumb-init
ENV NODE_ENV production
WORKDIR /usr/src/app
COPY --chown=node:node . /usr/src/app
RUN npm ci --only=production
RUN npm cache clean --force
EXPOSE 3002
CMD ["node", "./src/app.js" ]

Upvotes: 3

Related Questions