Oracle on Alpine linux

14,647

Solution 1

I share my version of docker that I made to work with the latest version of alpine and instantclient basiclite. The size of the docker image is 124 mb.

I share my github where you can download it

Docker + alpine + Instantclient Basiclite

Or you can see below the content of the dockerfile

FROM alpine:latest
# Install Instantclient Basic Light Oracle and Dependencies
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

Solution 2

I'd recommend using an operating system supported by Oracle, thus avoiding the headache of hacking Alpine and the uncertainty that it won't fall over at a critical time. And thus giving you some confidence your business won't be negatively impacted. Try https://github.com/oracle/docker-images/tree/master/OracleInstantClient

Other comments

  • Don't set ORACLE_HOME when using Instant Client. That variable is for full software installs.
  • Use ldconfig to set the system library path, see the Instant Client installation instructions e.g. here.
  • Use Instant Client 19, which can connect to the same DB versions that 12.2 can. (19 is really the renamed terminal 12.2 release in the new versioning system)
  • Using Oracle Linux Docker images has the advantage that it will download and install the 19 Instant Client without you having to manually do the download.

See this blog for info about the 'slim' Oracle Linux container it uses.

Solution 3

I might be late to answer this. I got the same problem of having a alpine base image and add oracle client to that. So i came up with this solution - https://github.com/Shrinidhikulkarni7/OracleClient_Alpine

Here is the Dockerfile, but you would also need the shell script in it for it to work.

FROM alpine:latest

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

ADD script.sh /root/script.sh

RUN /root/script.sh

Over here I'm directly downloading the oracle client inside image, setting the path, adding packages and finally using the shell script for creating symbolic link.

Share:
14,647

Related videos on Youtube

Norgul
Author by

Norgul

I'm cool

Updated on June 04, 2022

Comments

  • Norgul
    Norgul almost 2 years

    I am trying to install OCI8 extension on my Alpine Linux Docker environment. Although there are several places saying it won't work, there are some which say it actually does. I have a 3.4 version and for corporate reasons it is staying like that for now.

    I have done this within my Docker conf:

    # Install Oracle Client and build OCI8 (Oracel Command Interface 8 - PHP extension)
    USER root
    ENV LD_LIBRARY_PATH=/usr/local/instantclient
    ENV ORACLE_HOME=/usr/local/instantclient
    
    RUN apk update && apk upgrade
    RUN apk add musl-dev libaio autoconf && apk add --update make
    
    ## Unzip Instant Client v12
    RUN pecl channel-update pecl.php.net
    COPY instantclient_12_2.zip /var/www/html/instantclient_12_2.zip
    RUN unzip -d /usr/local/ /var/www/html/instantclient_12_2.zip
    RUN ln -s /usr/local/instantclient_12_2 /${ORACLE_HOME} && \
        ln -s /${ORACLE_HOME}/libclntsh.so.* /${ORACLE_HOME}/libclntsh.so && \
        ln -s /${ORACLE_HOME}/libocci.so.* /${ORACLE_HOME}/libocci.so && \
        ln -s /${ORACLE_HOME}/lib* /usr/lib && \
        ln -s /${ORACLE_HOME}/sqlplus /usr/bin/sqlplus &&\
        ln -s /usr/lib/libnsl.so.2.0.0  /usr/lib/libnsl.so.1
    
    RUN apk add gcc; exit 0 # This has a history of failing sometimes
    
    RUN echo "instantclient,/usr/local/instantclient" | pecl install oci8 &&\
        echo 'extension=oci8.so' > /usr/local/etc/php/conf.d/30-oci8.ini &&\
        rm -rf /tmp/*.zip /var/cache/apk/* /tmp/pear/
    

    Now the build passes, and it looks okay, however when I do a php -v I am getting the following:

    PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20160303/oci8.so' - Error loading shared library libnsl.so.1: No such file or directory (needed by /usr/local/instantclient/libclntsh.so.12.1) in Unknown on line 0

    PHP version is 7.1.12.

    What I've tried is doing apk add libnsl but this returns me this error:

    ERROR: unsatisfiable constraints: so:libtirpc.so.3 (missing):

    So I tried also adding apk add libtirpc-dev (the 'plain' libtirpc isn't available for my version or something), but that changed nothing.

    Any clues?

  • Norgul
    Norgul almost 5 years
    While it is common sense switching to something that may support it, the reasoning behind this is because a large container is made of our corporate product and switch is not trivial (it's been a long time since you commented this, but I guess better answering late than never :))
  • Drumbeg
    Drumbeg almost 4 years
    I think for a lot of people the Oracle Client would make up just one component of a Docker image, so steering towards Oracle Linux just for Oracle Client compatibility may not be the answer for some. Personally, I am using Oracle Linux based Docker images that utilise the client, but have found that in some cases it is Oracle Linux that doesn't provide the proper support for the other tools I need! Is there something specifically about Alpine that is problematic?
  • Meki
    Meki almost 4 years
    Getting the instantclient to work on everything else than Oracle Linux is problematic to say the least. I tend to choose the path of least resistance...
  • mvorisek
    mvorisek over 3 years
    how to build pdo_oci php extension with it?
  • Johan Boulé
    Johan Boulé almost 3 years
    Why an external script rather than a run command ?
  • Johan Boulé
    Johan Boulé almost 3 years
    Why are you mixing musl and glibc at the same time ?
  • Shrinidhi Kulkarni
    Shrinidhi Kulkarni almost 3 years
    I have updated it on GitHub. Totally forgot to update here @JohanBoulé
  • Shrinidhi Kulkarni
    Shrinidhi Kulkarni almost 3 years
    @mvorisek Not really sure about it. If you know, please send a PR.
  • Johan Boulé
    Johan Boulé almost 3 years
    @ShrinidhiKulkarni I don't know whether you used OCI (C API) or OCCI (C++ API), but after extensive tries, I concluded that there's no way to make Musl compatible with OCCI, and that we need to install the full GLibC "stack" in a separate directory, which defeats the purpose of using Alpine in the first place.
  • Atul Kumar
    Atul Kumar about 2 years
    It does not work for sdlldr utility, gives below error: Error relocating ./sqlldr: __printf_chk: symbol not found Error relocating ./sqlldr: __strncat_chk: symbol not found Error relocating ./sqlldr: __vsprintf_chk: symbol not found Error relocating ./sqlldr: __fprintf_chk: symbol not found