Currently, I have a strange issue in that when I try to connect to the Oracle Database container from an Apache Container, I will get "TNS: Connect Timeout Occurred" from oci_error method. My PHP code is as follow:
<?php
$objConnect = oci_connect('SYSTEM', 'xxxxxxxxxx', 'x.x.x.x/xxxxx');
if($objConnect)
{
echo "from Docker Oracle Server Connected" . PHP_EOL;
}
else
{
echo "Cannot connect to Oracle Server" . PHP_EOL;
var_dump( oci_error() );
}
?>
My docker code to run Oracle Database is:
docker run --name orcl_12c_r_1 -p 1521:1521 -p 5500:5500 -e ORACLE_SID=xxxxx oracle/database:12.1.0.2-se2
And I brought my Apache up with this docker-compose.yml:
version: '3'
services:
oraclelinuxphp:
build:
context: ./oraclelinuxphp
dockerfile: Dockerfile # install httpd and PHP here.
ports:
- "8080:80"
volumes:
- ./web:/var/www/html
However, this issue is resolved when I added network_mode host to the docker-compose.yml :
version: '3'
services:
oraclelinuxphp:
build:
context: ./oraclelinuxphp
dockerfile: Dockerfile # install httpd and PHP here.
ports:
- "8080:80"
volumes:
- ./web:/var/www/html
network_mode: "host"
I am still a rookie when it comes to Docker, and from here, I believe I am missing something in Docker. I could connect to the Oracle Database in the container on the server from Oracle SQL Developer app on my desktop without any problem. In addition, I also tried the non-Docker route, and the non-Docker PHP could also connect to this Oracle Database as well.
So I believe this is Docker issue. What am I missing here? How can I make it so the Apache Container could connect to the Oracle Database Container in this case?
Note: I am using :
- centos-release-7-7.1908.0.el7.centos.x86_64
- Docker version 19.03.8, build afacb8b
- Oracle Database 12.1.0.2 from https://github.com/oracle/docker-images