As part of our work, we were asked to create an Laravel application using existing Oracle Database data. However, we cannot connect to Oracle from either the Docker container we are using for development or the Ubuntu 22.04 machine we are developing on.
The following code is the docker-compose.yml and Dockerfile used to create the container. In the code below, instantclient uses 11.2.0.4.0 to match the database version, but the latest version, 21.11.0.0.0, is still the same.
docker-compose.yml
version: '3.9'
services:
xxxxx_calender_php:
container_name: xxxxx_calender_php
build:
context: ./php
ports:
- '8087:80'
volumes:
- ./src:/var/www/html
- ./apache/default.conf:/etc/apache2/sites-enabled/000-default.conf
- ./apache/logs:/var/log/apache2
restart: always
extra_hosts:
- "xxxxx:xxx.xx.xxx.x"
Dockefile
FROM php:8.0-fpm
COPY php.ini /usr/local/etc/php/
ENV LD_LIBRARY_PATH /usr/local/instantclient/
ENV TNS_ADMIN /usr/local/instantclient/
COPY instantclient-basic-linux.x64-11.2.0.4.0.zip /tmp
COPY instantclient-sdk-linux.x64-11.2.0.4.0.zip /tmp
COPY instantclient-sqlplus-linux.x64-11.2.0.4.0.zip /tmp
RUN apt-get update \
&& apt-get install -y git openssh-client zlib1g-dev mariadb-client vim libzip-dev libpq-dev libonig-dev libpng-dev libjpeg-dev zip unzip \
&& docker-php-ext-configure gd --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd \
&& docker-php-ext-install zip pdo_pgsql mbstring bcmath
#Composer install
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
RUN php composer-setup.php
RUN php -r "unlink('composer-setup.php');"
RUN mv composer.phar /usr/local/bin/composer
#Oracle Client
RUN apt-get install -y libaio1 wget && \
unzip /tmp/instantclient-basic-linux.x64-11.2.0.4.0.zip -d /usr/local/ && \
unzip /tmp/instantclient-sdk-linux.x64-11.2.0.4.0.zip -d /usr/local/ && \
unzip /tmp/instantclient-sqlplus-linux.x64-11.2.0.4.0.zip -d /usr/local/ && \
ln -s /usr/local/instantclient_11_2 /usr/local/instantclient && \
ln -s /usr/local/instantclient_11_2/libclntsh.so.11.1 /usr/local/instantclient/libclntsh.so && \
export LD_LIBRARY_PATH=/usr/local/instantclient && \
docker-php-ext-configure oci8 --with-oci8=instantclient,/usr/local/instantclient && \
docker-php-ext-install oci8 && \
docker-php-ext-configure pdo_oci --with-pdo-oci=instantclient,/usr/local/instantclient,11.1 && \
docker-php-ext-install pdo_oci && \
rm -rf /usr/local/*.zip
RUN echo "export ORACLE_HOME=/usr/local/instantclient \n\
export PATH=/usr/local/instantclient:${PATH}" >> ~/.bashrc
ENV COMPOSER_ALLOW_SUPERUSER 1
ENV COMPOSER_HOME /composer
ENV PATH $PATH:/composer/vendor/bin
#WORKDIR /var/www
# WORKDIR /workspace
RUN composer global require "laravel/installer"
RUN groupadd --force -g 1000 xxxx
RUN useradd -ms /bin/bash --no-user-group -g xxxx -u 1000 xxxx
Laravel .env
DB_CONNECTION=oracle
DB_HOST=xxx.xx.xxx.x
DB_PORT=1521
DB_DATABASE=xxxxx
DB_USERNAME=xxxxx
DB_PASSWORD=xxxxx
The following ORA-12541
error occurred from both the Docker container and Ubuntu itself.
xxxx@xxxxxxxxxxx:~$ sqlplus xxxxx/xxxxx@//xxx.xx.xxx.x:1521/xxxxx
SQL*Plus: Release 21.0.0.0.0 - Production on Thu Oct 19 16:50:45 2023
Version 21.11.0.0.0
Copyright (c) 1982, 2022, Oracle. All rights reserved.
ERROR:
ORA-12541: TNS:no listener
root@93ee8a37f9e7:/var/www/html/prinos_calender# php artisan tinker
Psy Shell v0.11.22 (PHP 8.0.30 — cli) by Justin Hileman
> DB::connection()->getConfig();
WARNING oci_connect(): ORA-12541: TNS:no listener in vendor/yajra/laravel-pdo-via-oci8/src/Pdo/Oci8.php on line 144.
Yajra\Pdo\Oci8\Exceptions\Oci8Exception ORA-12541: TNS:no listener.
>
However, Windows machines connected to the same network can connect normally.
PS C:\Users\xxxxxxx> sqlplus xxxxxx/xxxxxx@//xxx.xx.xxx.x:1521/xxxxx
SQL*Plus: Release 12.1.0.1.0 Production on 木 10月 19 17:12:02 2023
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Oracle Database 11g Release 11.2.0.1.0 - 64bit Production
に接続されました。
SQL>
What is the problem?