Simon Leung
Simon Leung

Reputation: 25

dockerfile setup for php connecting to Oracle

I have problem setting up the php connecting to Oracle databases, the following message is encountered:

Step 4/7 : ADD instantclient-basic-linux.x64-12.1.0.2.0.zip /opt/oracle
ERROR: Service 'php-apache' failed to build: ADD failed: stat /var/lib/docker/tmp/docker-builder164874438/instantclient-basic-linux.x64-12.1.0.2.0.zip: no such file or directory

Dockerfile

FROM php:7.4-apache
RUN docker-php-ext-install pdo pdo_mysql mysqli

ORACLE oci

RUN mkdir /opt/oracle \
    && cd /opt/oracle
ADD instantclient-basic-linux.x64-12.1.0.2.0.zip /opt/oracle
ADD instantclient-sdk-linux.x64-12.1.0.2.0.zip /opt/oracle

Install Oracle Instant Client

RUN  unzip /opt/oracle/instantclient-basic-linux.x64-12.1.0.2.0.zip -d /opt/oracle \
    && unzip /opt/oracle/instantclient-sdk-linux.x64-12.1.0.2.0.zip -d /opt/oracle \
    && ln -s /opt/oracle/instantclient_12_1/libclntsh.so.12.1 /opt/oracle/instantclient_12_1/libclntsh.so \
    && ln -s /opt/oracle/instantclient_12_1/libclntshcore.so.12.1 /opt/oracle/instantclient_12_1/libclntshcore.so \
    && ln -s /opt/oracle/instantclient_12_1/libocci.so.12.1 /opt/oracle/instantclient_12_1/libocci.so \
    && rm -rf /opt/oracle/*.zip

Install Oracle extensions

RUN echo 'instantclient,/opt/oracle/instantclient_12_1/' | pecl install oci8 \ 
      && docker-php-ext-enable \
               oci8 \ 
       && docker-php-ext-configure pdo_oci --with-pdo-oci=instantclient,/opt/oracle/instantclient_12_1,12.1 \
       && docker-php-ext-install \
               pdo_oci 

Upvotes: 0

Views: 2879

Answers (1)

Christopher Jones
Christopher Jones

Reputation: 10496

Your error sounds like something simple with paths or not having the zip file where you think it is.

I suggest you look at Oracle's sample Dockerfiles for PHP: https://github.com/oracle/docker-images/tree/master/OracleLinuxDevelopers e.g. this Dockerfile.

Also check out Docker for Oracle Database Applications in Node.js and Python, which shows Instant Client.

Do you really need to use Instant Client 12.1? Oracle Instant Client 19c can connect to Oracle DB 11.2 or later and is easier to get (it doesn't need a click through to download).

Upvotes: 1

Related Questions