Error using Oracle Instant Client Docker image - linux

our app is nodejs based and needs to query Oracle DB, so we install NPM oracledb package. So our Docker image is based on oracle instant client, the Docker file looks like following:
FROM frolvlad/alpine-glibc
RUN apk update && apk add libaio
COPY instantclient_12_1.zip ./
RUN unzip instantclient_12_1.zip
RUN mv instantclient_12_1/ /usr/lib/
RUN rm instantclient_12_1.zip
RUN ln /usr/lib/instantclient_12_1/libclntsh.so.12.1 /usr/lib/libclntsh.so
RUN ln /usr/lib/instantclient_12_1/libocci.so.12.1 /usr/lib/libocci.so
RUN ln /usr/lib/instantclient_12_1/libociei.so /usr/lib/libociei.so
RUN ln /usr/lib/instantclient_12_1/libnnz12.so /usr/lib/libnnz12.so
ENV ORACLE_BASE /usr/lib/instantclient_12_1
ENV LD_LIBRARY_PATH /usr/lib/instantclient_12_1
ENV TNS_ADMIN /usr/lib/instantclient_12_1
ENV ORACLE_HOME /usr/lib/instantclient_12_1
RUN apk add nodejs npm
RUN mkdir -p /var/app
WORKDIR /var/app
ADD package.json /var/app
COPY . /var/app
CMD ["npm","start"]
But when our app starts using 'oracledb' NPM package, it got following error:
init() error: DPI-1047: Cannot locate a 64-bit Oracle Client library: "Error loading shared library libnsl.so.1: No such file or directory (needed by /usr/lib/libclntsh.so)". 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
So Oracle client couldn't find libnsl.so.1 even thought it should come with glibc, and I can see that it is under:
'/usr/glibc-compat/lib'.
Any ideas how to fix this? Thanks in Advance.

# 1. Install dependencies
FROM node:8.15 as cache-package
COPY package.json /srv/src/package.json
WORKDIR /srv/src
RUN yarn install
# 2.
FROM node:8.15 as builder
# 1. Update everything on the box
RUN apt-get update && \
apt-get install sudo
#RUN apk --update add libaio bc net-tools
RUN sudo apt-get install unzip
RUN sudo apt-get install wget
RUN sudo apt-get install git
# 3. Install oracle client
RUN mkdir -p /opt/oracle
# 3.1 Get oracle client
WORKDIR /opt/oracle
RUN wget -O /opt/oracle/instantclient_18_3_linux.zip http://YOUR_URL_TO_DOWNLOAD_THE_CLIENT/instantclient_18_3_linux.zip
RUN sudo unzip /opt/oracle/instantclient_18_3_linux.zip
# 3.2 Configure oracle client to work with node
RUN sudo sh -c "echo /opt/oracle/instantclient_18_3_linux > /etc/ld.so.conf.d/oracle-instantclient.conf"
RUN sudo cat /etc/ld.so.conf.d/oracle-instantclient.conf
FROM node:8.15
RUN apt-get update && \
apt-get install sudo
RUN sudo apt-get install libaio1
RUN mkdir -p /srv/src/logs
RUN mkdir -p /srv/logs
RUN mkdir -p /opt/oracle
# 4. Set the working directory
# 5. Copy our project & install our dependencies
COPY --from=cache-package /srv/src /srv/src
COPY --from=builder /opt/oracle/instantclient_18_3_linux /opt/oracle/instantclient_18_3_linux
COPY --from=builder /etc/ld.so.conf.d/oracle-instantclient.conf /etc/ld.so.conf.d/oracle-instantclient.conf
RUN sudo ldconfig
RUN ln -sf /usr/share/zoneinfo/WET /etc/localtime
COPY . /srv/src
WORKDIR /srv/src
# 6. Start the app
CMD yarn start
Here is my dockerfile working fine, the srv/src is my directory where I have my code, just change for yours and it should work.
I have the same problem as you the past two days and now it works.

Related

Issue with node-oracledb inside a Docker container

I have a Nest.js app which is connecting to an Oracle database through TypeORM and i'm trying to containerize my application using Docker. So the issue here is that when the app is not containerized it works fine but when I do, I get the following error.
[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)
I made sure to add the dependencies that are needed for the Oracle thin client in my Dockerfile as follows
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 ./
I am not sure what else to add here to make this work. I got some of the instructions on what to add for oracle client from here https://oracle.github.io/node-oracledb/INSTALL.html#docker
It looks like you are trying to use a multi-stage build. I discussed this in "Node.js Dockerfile Example 3" in my blog posst Docker for Oracle Database Applications in Node.js and Python.
You could try something like:
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
Overall this is probably not worth the complexity. Look at the other example in the blog post. Or use Oracle's Dockerfile: https://github.com/oracle/docker-images/tree/master/OracleLinuxDevelopers/oraclelinux7/nodejs/12-oracledb

can't do copy using docker and getting error as directory not found?

When I'm trying to install packages using docker
I'm getting the following error
COPY failed: stat /var/lib/docker/overlay2/7f434dda3e872abd56226080297095cbc3ebd1decef703550c2c12fead4a6e94/merged/home/site/wwwroot: no such file or directory
here is my dockerfile
COPY . /home/site/wwwroot
FROM ubuntu
# ...
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && \
apt-get -y install gcc mono-mcs && \
rm -rf /var/lib/apt/lists/*
COPY --from=0 /home/site/wwwroot /home/site/wwwroot
RUN cd /home/site/wwwroot && pip install -r requirements.txt
how to resolve it?
You can also try : Just make sure your pip path is correct, do which pip to make sure what the pip path is.
Then put this in your docker file instead of the last line:
...
RUN /usr/bin/pip -r /home/site/wwwroot/requirements.txt
Let me know if you don't understand my answer.

Deploying node.js web app along with docker

WE have a node.js web app.We have deployed it on server with docker.
Its working fine with node version 0.10.25. But right now i have decided it to run on latest version of node 6.5.0
To accomplish this i modified the docker file which is now looking like below
FROM ubuntu:14.04
RUN echo 'deb http://security.ubuntu.com/ubuntu trusty-security main' | sudo tee -a /etc/apt/sources.list
RUN sudo apt-get update
RUN sudo apt-get install linux-libc-dev curl git-core krb5-multidev libkrb5-dev -y
RUN sudo curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
RUN sudo apt-get install nodejs -y
RUN sudo ln -sf /usr/bin/nodejs /usr/bin/node
RUN ["/bin/bash", "-c", "node -v"]
RUN sudo npm cache clean
RUN sudo npm install -g bower -y
RUN sudo npm install -g gulp -y
#RUN sudo npm install -g node-sass
#RUN sudo npm install -g eslint -y
#RUN sudo npm install -g htmllint -y
RUN cd /root; git clone -b masterclone https://consultancy:Admin23#github.com/newapp/web.git
RUN cd /root/web; sudo npm install; sudo bower install --allow-root; gulp clean-build-app-prod
EXPOSE 8000
CMD cd /root/web; NODE_ENV=production node server.js
Everything went fine except the below line which i guess causing the problem
"The command '/bin/sh -c cd /root/web; sudo npm install; sudo bower install --allow-root; gulp clean-build-app-prod' returned a non-zero code: 1"
Use the official node image. Here a example file.
FROM node:6.5
# Enviroment variables
ENV NPM_CONFIG_LOGLEVEL warn
ENV USER node
ENV HOMEDIR /data
# add user node and change dir working dir
RUN useradd -ms /bin/bash ${USER}
RUN mkdir -p ${HOMEDIR}
WORKDIR ${HOMEDIR}
# install all dependencies
COPY package.json ./
RUN npm install --production
# add node content
COPY . .
USER node
EXPOSE 8000
CMD ["npm", "start"]
It's probably simpler to base your file off of the official NodeJS image. For v6.5, that means that FROM ubuntu:14.04 becomes FROM node:6.5.
Also, instead of doing RUN cd /root/web over and over, you might want to change the working directory with WORKDIR /root/web.

Docker with Node.js and Express.js

I'm trying to use docker with my node application, my Dockerfile looks like this:
RUN apt-get update
RUN apt-get -y install build-essential
RUN apt-get install -y nodejs
RUN apt-get install -y npm
ADD . /src
RUN cd /src && npm install
EXPOSE 8080
CMD ["node","/src/app.js"]
but after running docker build when npm install is running after trying to install https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.2.tgz I get an error:
The command 'bin/sh -c /src && npm install' returned a non-zero code : 1
What can cause such an issue? I've already tried to install node-legacy instead of node and it didn't work
Try this:
# put this line on your code (if you are using ubuntu)
# this make a link from nodejs to node to add compatibility on ubuntu OS
RUN ln -s /usr/bin/nodejs /usr/bin/node
# set your current directory with WORKDIR
WORKDIR /src
RUN sudo npm install

Getting "can't cd" error when when building using dockerfile

This is the complete dockerfile
FROM ubuntu:12.04
# Create directory
RUN mkdir -p /dir/subdir
# Download wget
RUN apt-get install -y wget
# Make sure package is up to date
RUN apt-get update
# Install nodejs
WORKDIR /dir
RUN wget http://nodejs.org/dist/v0.10.26/node-v0.10.26-linux-x64.tar.gz
RUN tar -zxf node-v0.10.26-linux-x64.tar.gz
RUN cd /node-v0.10.26-linux-x64 && ./configure
RUN cd /node-v0.10.26-linux-x64 && make
RUN cd /node-v0.10.26-linux-x64 && make install
# Update again
RUN apt-get-update
# Copy all the files
ADD dir/subdir dir/subdir
EXPOSE 8080
CMD ["node", "/dir/subdir/index.js"]
This is part of the log where it gets an error
Step 6 : RUN tar -zxf node-v0.10.26-linux-x64.tar.gz
---> Running in xxxxxxx
---> xxxxxxxxxxxxxx
Removing intermediate container xxxxxxxxxxxx
Step 7 : RUN cd /node-v0.10.26-linux-x64 && ./configure
---> Running in xxxxxxxx
[91m/bin/sh: 1: cd: can't cd to /node-v0.10.26-linux-x64
[0m
The command [/bin/sh -c cd /node-v0.10.26-linux-x64 && ./configure] returned a non-zero code: 2
Does anyone know what the error 2 means and how to fix it?
This time I tested it.
FROM ubuntu:12.04
# Create directory
RUN mkdir -p /dir/subdir
# Make sure package is up to date
RUN apt-get update
# Install dependencies
RUN apt-get install -y build-essential openssl libssl-dev pkg-config python
# Install nodejs
WORKDIR /dir
ADD http://nodejs.org/dist/v0.10.29/node-v0.10.29.tar.gz /dir/
RUN tar -zxf node-v0.10.29.tar.gz
WORKDIR /dir/node-v0.10.29
RUN ./configure && make && make install
WORKDIR /dir
# Copy all the files
ADD dir/subdir dir/subdir
EXPOSE 8080
CMD ["node", "/dir/subdir/index.js"]
Docker (v1.0.0) will use WORKDIR for subsequent RUN. cd /node-v0.10.26-linux-x64 won't work as the untar occured in /dir.

Resources