Issue with node-oracledb inside a Docker container - node.js

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

Related

Update nifi Controllers and Processors through API without IDs

I need to automate nifi bootstraping using docker(specifically nifi-1.17.0).
I want to be able to load a template on each new container instance andi nstead of running the new instance and then logging in to the UI and changing all settings manually, I want to do it automatically within a bash script.
What I need is to update a controller service's fields, and 1 processor's property.
I understand that my workflow is such:
stop processor
disable controller service
update controller service
enable controller service
start processor
and
stop processor
update property
start processor
but I also understand that each time I use the template, all processors and controllers have a different ID.
How can I automate this or use the API if I dont know what ID my processors and controllers will have?
And how do I upload a template and use it through the API?
Thanks in advance to all!
I am running the container using the following Dockerfile:
FROM ubuntu:20.04
# Args
ENV NIFI_SERVER_IP "some ip"
ENV BASE_DIR "some path"
# Create our workdir
RUN mkdir -p ${BASE_DIR} && cd ${BASE_DIR}
# Set workdir
WORKDIR ${BASE_DIR}
# Copy bootstrap to workdir
COPY script.sh .
# Run the bootstrap
RUN apt-get update && apt-get install curl -y
RUN ./script.sh ${NIFI_SERVER_IP}
# Set workdir to new workdir
#WORKDIR ${BASE_DIR}/something i didnt want to share/nifi-1.17.0/bin
# Command to run when container starts
#CMD ["./nifi.sh","start"]
and my script is:
#!/bin/bash
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install dialog
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends tzdata
DEBIAN_FRONTEND=noninteractive apt-get install wget -y
DEBIAN_FRONTEND=noninteractive apt-get install git-all -y
wget https://archive.apache.org/dist/nifi/1.17.0/nifi-1.17.0-bin.zip
DEBIAN_FRONTEND=noninteractive apt install unzip -y
unzip nifi-1.17.0-bin.zip
cd nifi-1.17.0
sed -i 's/127.0.0.1/0.0.0.0/g' conf/nifi.properties
sed -i "s/nifi.web.proxy.host=/nifi.web.proxy.host=$1:8443/g" conf/nifi.properties
DEBIAN_FRONTEND=noninteractive apt-get install java-11-openjdk -y
DEBIAN_FRONTEND=noninteractive apt-get install openjdk-11 -y
DEBIAN_FRONTEND=noninteractive apt-get install openjdk-11-jre -y
echo "export JAVA_HOME='/usr/lib/jvm/java-11-openjdk-amd64/'" >> ~/.bashrc
cd bin
./nifi.sh start
./nifi.sh set-single-user-credentials admin nifipassword1
./nifi.sh stop
You should name each Controller or Processor object in your flow uniquely, and search for them by that name in a setup script. Some of these actions are possible via the NiFi CLI, however I would recommend you automate more complex NiFi Flow configurations via the community Python client NiPyAPI (I am the main author)

Cannot install pyodbc in docker and getting error command 'gcc' failed with exit status 1

I'm trying install pyodbc in docker running inside linux container
But I'm getting the following error
Click here to view the image
src/pyodbc.h:56:10: fatal error: sql.h: No such file or directory
#include <sql.h>
^~~~~~~
compilation terminated.
error: command 'gcc' failed with exit status 1
----------------------------------------
ERROR: Failed building wheel for pyodbc
Here is my dockerfile
FROM mcr.microsoft.com/azure-functions/python:2.0
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true
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/*
FROM python
RUN apt-get update && apt-get install -y python3-pip
# RUN /usr/bin/pip -r /home/site/wwwroot/requirements.txt
# WORKDIR /home/site/wwwroot
COPY --from=0 /home/site/wwwroot /home/site/wwwroot
RUN cd /home/site/wwwroot && pip install -r requirements.txt
Note: I'm going push the code to the azure functionapp in linux machine
I had the same issue, I added the below code in my docker file, and it started working. Microsoft docker image is missing unixodbc-dev, so you need to install separately using the below command.
RUN apt-get update && apt-get install -y --no-install-recommends \
unixodbc-dev \
unixodbc \
libpq-dev
This is the setup that worked for me:
# pull official base image
FROM python:3.9.2-slim-buster
# install system dependencies
RUN apt-get update \
&& apt-get -y install gcc \
&& apt-get -y install g++ \
&& apt-get -y install unixodbc unixodbc-dev \
&& apt-get clean
And the pyodbc package was installed successfully.
The error is:
src/pyodbc.h:56:10: fatal error: sql.h: No such file or directory
#include <sql.h>
This is telling you that you are missing a file sql.h. Looking at the documentation for PyODBC, it appears to require the UnixODBC development environment.
There are installation instructions at the above link for most major distributions. You will need to update your Dockerfile to install the unixodbc-dev package.
This link is also helpful, you are missing mandatory files to needed to install. Add the below command for Debain to Dockerfile , the link has all solutions
RUN apt-get update && apt-get install -y gcc unixodbc-dev
https://github.com/mkleehammer/pyodbc/issues/165
The consolidated list of dependencies needed for pyodbc can be found in the documentation. Make sure all of these are installed.
PYODBC installation documentation

Error using Oracle Instant Client Docker image

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.

Trouble installing NodeJS on Kali Linux docker image

I am trying to create a docker image based on the Kali Linux base image, and I need to install NodeJS as a dependency for my application.
Here's my Dockerfile:
FROM kalilinux/kali-linux-docker
RUN apt-get update -y && \
apt-get dist-upgrade -y && \
apt-get autoremove -y && \
apt-get clean -y
RUN apt-get install curl -y
RUN curl --silent --location https://rpm.nodesource.com/setup_8.x | bash - \
&& apt-get install nodejs -y
RUN npm i -g npm
ENV NODE_ENV production
WORKDIR /root/app
COPY . .
RUN npm i
EXPOSE 4000
ENTRYPOINT ["npm", "start"]
However, I hit the following error trying to install NodeJS:
Step 4/11 : RUN curl --silent --location https://rpm.nodesource.com/setup_8.x | bash - && apt-get install nodejs -y
---> Running in a63e56802eba
## Installing the NodeSource Node.js 8.x LTS Carbon repo...
## Inspecting system...
## You don't appear to be running an Enterprise Linux based system,
please contact NodeSource at https://github.com/nodesource/distributions/issues
if you think this is incorrect or would like your distribution to be considered
for support.
The command '/bin/sh -c curl --silent --location https://rpm.nodesource.com/setup_8.x | bash - && apt-get install nodejs -y' returned a non-zero code: 1
Admittedly I'm confused by a few things... namely that I was under the impression that NodeJS was already installed on Kali Linux (I have a VirtualBox VM using Debian 64-bit where it exists). I went as far as trying to install the kali-linux-all metapackage, but NodeJS/npm don't seem to exist.
Am I simply misunderstanding some basic premise of Docker and/or Kali Linux? Is there any other way to install NodeJS into my container?
I still don't fully understand why NodeJS is installed on my VM but not the base Kali docker image... but in any case I did manage to unblock myself.
First, I was pulling down a NodeJS installation script from nodesource which required rpm -- I found a different script that works without it. However the new script also required that I install gnupg.
Here's my updated Dockerfile:
FROM kalilinux/kali-linux-docker
RUN apt-get update -y && \
apt-get dist-upgrade -y && \
apt-get autoremove -y && \
apt-get clean -y
RUN apt-get -y install curl gnupg
RUN curl --silent --location https://deb.nodesource.com/setup_8.x | bash - \
&& apt-get install nodejs -y
RUN npm i -g npm
ENV NODE_ENV production
WORKDIR /root/app
COPY . .
RUN npm i
EXPOSE 4000
ENTRYPOINT ["npm", "start"]

Upgrade or install Ghostscript 9.21 in docker image node:7

I'm installing Ghostscript into a docker image and want to use it with ghostscript4js which requires for some functionality at least Ghostscript 9.21.
I'm using this in my docker file which installs Ghostscript 9.06
FROM node:7
ARG JOB_TOKEN
RUN apt-get update && \
apt-get install -y pdftk
ENV APP_DIR="/usr/src/app" \
JOB_TOKEN=${JOB_TOKEN} \
APP_DIR="/usr/src/app" \
GS4JS_HOME="/usr/lib"
COPY ./ ${APP_DIR}
# Step 1: Install App
# -------------------
WORKDIR ${APP_DIR}
# Step 2: Install Python, GhostScript and npm packages
# -------------------
ARG CACHE_DATE=2017-01-01
RUN \
apt-get update && \
apt-get install -y build-essential make gcc g++ python python-dev python-pip python-virtualenv && \
apt-get -y install ghostscript && apt-get clean && \
apt-get install -y libgs-dev && \
rm -rf /var/lib/apt/lists/*
RUN npm install
# Step 3: Start App
# -----------------
CMD ["npm", "run", "start"]
How do I install or upgrade to a higher Ghostscript version in a docker image?
Seems like the distro you are using (since you use apt-get) is only on 9.06. Not surprising, many distros remain behind the curve, especially long term support ones.
If you want to use a more recent version of Ghostscript, then you could nag the packager to update. And you know, 9.06 is 5 years old now.....
Failing that you'll have to build it yourself. Git clone the Ghostscript repository, cd ghostpdl, ./autogen.sh, make install. That of course gets the current bleeding edge source, for a release version you'll have to pull from one of the tags (we tag the source for each release).
Or build it yourself locally and put it somewhere that your docker image can retrieve it from.
IMO if you are going to use a version other than the one provided by the packager of your distro, you may as well use the current release. That's currently 9.22 and will be 9.23 in a few weeks.

Resources