Shrinidhikulkarni7 / OracleClient_Alpine

Installing oracle client for alpine docker image
MIT License
45 stars 24 forks source link

Cannot locate a 64-bit Oracle Client library #2

Closed SutharMukesh closed 4 years ago

SutharMukesh commented 4 years ago

Hi there, I am currently trying to dockerize my REST API server written in nodejs which requires oracle client. my application works with base image jessie but takes alot of size, so I was trying to build the image on alpine, I came across your repo which offers oracle client on the alpine image.

I'm stuck with an error, would appreciate if you may look into it.

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 /lib/libclntsh.so)". See https://oracle.github.io/odpi/doc/installation.html#linux for help

Dockerfile

FROM node:10-alpine

ENV LD_LIBRARY_PATH=/lib

RUN wget https://download.oracle.com/otn_software/linux/instantclient/193000/instantclient-basic-linux.x64-19.3.0.0.0dbru.zip && \
    unzip instantclient-basic-linux.x64-19.3.0.0.0dbru.zip && \
    cp -r instantclient_19_3/* /lib && \
    rm -rf instantclient-basic-linux.x64-19.3.0.0.0dbru.zip && \
    apk add libaio && \
    cd /lib && \
    ln -s libnsl.so.2 /usr/lib/libnsl.so.1 && \
    ln -s libc.so /usr/lib/libresolv.so.2

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install

COPY . .

EXPOSE 3004

CMD ["node","index.js"]
Shrinidhikulkarni7 commented 4 years ago

Do you need it with 19.03 or 18.03 will be okay for you? I saw oracle has changed some stuff for 19.03

SutharMukesh commented 4 years ago

okay, will try creating with 18.03.

luisrudge commented 4 years ago

I'm having the same issue :( Sadly, I have no idea how to fix this hehe. I tried to follow Oracle's own readme but it didn't work.

Shrinidhikulkarni7 commented 4 years ago

@luisrudge this problem for some reason comes with oracle client 19.03.

I suggest you to download 18.03, use a COPY command to place it in docker container and build it.

If you want me to do it, please create a new issue, thank you.

luisrudge commented 4 years ago

Thanks, I ended up using a multistep docker file

FROM oraclelinux:7-slim as builder

#Instant Client Version
ARG release=19
ARG update=6

RUN yum -y install oracle-release-el7
RUN yum-config-manager --enable ol7_oracle_instantclient
RUN yum -y install 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 && \
    npm i -g nodemon

# Create app directory
WORKDIR /usr/src/app
# Copy the .js files from your host machine into the new app directory
ADD ./ ./

CMD ["node", "index.js"]
Shrinidhikulkarni7 commented 4 years ago

Looks good @luisrudge . What is size of your image now?

luisrudge commented 4 years ago
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
testoracle          latest              85c3bda1413e        4 seconds ago       301MB
Shrinidhikulkarni7 commented 4 years ago

@luisrudge not bad. i wanted alpine badly due to it's size

luisrudge commented 4 years ago

@Shrinidhikulkarni7 what's your image's size?

luisrudge commented 4 years ago

If I change to alpine, I save only 80mb

FROM oraclelinux:7-slim as builder

#Instant Client Version
ARG release=19
ARG update=6

RUN yum -y install oracle-release-el7
RUN yum-config-manager --enable ol7_oracle_instantclient
RUN yum -y install 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-alpine

# 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 wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub && \
    wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.31-r0/glibc-2.31-r0.apk && \
    apk add glibc-2.31-r0.apk && \
    apk add libaio

# Create app directory
WORKDIR /usr/src/app
# Copy the .js files from your host machine into the new app directory
ADD ./ ./

CMD ["node", "index.js"]

testoracle latest 32f81cbd905c 8 seconds ago 228MB

SutharMukesh commented 4 years ago

This repo looks promising to reduce image size significantly, I haven't tried it yet.