Not able to connect to db container

I am developing two docker containers one for my java application and another for oracle database.
I created docker compose file and able to start both containers. when i run my java application from my windows machine using javaws command, it didn’t work. i tried to check whether java application container is interacting with db container or not by logging into application container and executed “isql XE DEFMODWAS defmodwas -v” command and it returns
“[IM002][unixODBC][Driver Manager]Data source name not found and no default driver specified
[ISQL]ERROR: Could not SQLConnect”
below is my docker compose file, docker file for java application and db . please update what i am doing wrong
Docker compose file.

version: '3.8'

networks:
   oracle_net:
    external:
      name: oracle_net
      
volumes:
   oravolume9:
    external:
      name: oravolume9    
      
services:
    oracle_xe:
        image: redbdocker
        build:
            context: '.\oracle docker'
        hostname: oraclehost
        networks:
            oracle_net:
                aliases:
                    - oraclexe
        ports:
            - "1521:1521"
        volumes:
            - type: volume
              source: oravolume9
              target: /opt/oracle
              
        
    ruleeditor:
        depends_on:
            - oracle_xe
        image: reimage15
        hostname: rehost
        build:
            context: '.\REDocker'
        networks:
            oracle_net:
                aliases:
                    - oraclexe
        ports:
            - "9088:9088"
        links:
            - oracle_xe
        environment:
          - DATABASE_HOST=172.18.0.2
          - DATABASE_USER=DEFMODWAS
          - DATABASE_PASSWORD=india123
          - DATABASE_NAME=XE
          - DATABASE_PORT=1521

docker file for java application container:

FROM ibmcom/websphere-liberty:latest
USER root
ADD ./rtcc.ear /opt/ibm/wlp/usr/servers/defaultServer/apps
ADD ./rtccClient.war /opt/ibm/wlp/usr/servers/defaultServer/apps
RUN yum -y install unixODBC
RUN yum -y install libaio
RUN mkdir -pv /basic
COPY ./basicinstaclient/oracle-instantclient19.8-basic-19.8.0.0.0-1.x86_64.rpm /basic/
RUN rpm -i /basic/oracle-instantclient19.8-basic-19.8.0.0.0-1.x86_64.rpm
EXPOSE 9088

Docker file for DB:

FROM oraclelinux:6
USER root
RUN groupadd -g 501 oinstall \
  && groupadd -g 502 dba \
  && groupadd -g 503 oper \
  && useradd -m -g oinstall -G oinstall,dba,oper -u 501 oracle \
  && echo 'oracle:prasanth9323' | chpasswd


RUN yum -y install file openssl lsof sudo sysstat tree wget which
RUN yum -y install oracle-database-preinstall-18c
RUN mkdir -pv /install
COPY ./oracle/oracle-database-xe-18c-1.0-1.x86_64.rpm /install
ENV ORACLE_DOCKER_INSTALL=true \
    ORACLE_BASE=/opt/oracle \
    ORACLE_HOME=/opt/oracle/product/18c/dbhomeXE \
    PATH=/home/oracle/bin:/opt/oracle/product/18c/dbhomeXE/bin:$PATH \
    NLS_DATE_FORMAT="dd/mm/yyyy:hh24:mi:ss" \
    ORACLE_SID=XE
RUN cd /install \
 && yum -y localinstall oracle-database-*18c*  \
 && yum clean all \
 && rm -rf /install/oracle*.rpm
 EXPOSE 1521
COPY ./scripts/DM_create_tables_was.sql /install
COPY ./scripts/DM_inserts_was.sql /install
COPY ./scripts/oracle_start.sh /install
COPY ./scripts/bash.src /install
ENTRYPOINT [ "/bin/bash" , "/install/oracle_start.sh" ]

I am using javaws http://localhost:9088/rtccClient/rtcc.jnlp to run application

Your files are nearly unreadable if you don’t format them as code. What looks strange to me is that you use an IP address for the db host:

HI I changed the host name now still having the same issue.

environment:
- DATABASE_HOST=oraclehost
- DATABASE_USER=DEFMODWAS
- DATABASE_PASSWORD=india123
- DATABASE_NAME=XE
- DATABASE_PORT=1521

If your db runs in service oracle_xe then this is its name.
Why do you define networks and does this external volume oravolume9 really exist?

Hi, when two containers need to interact with each other they need to use same net work . so only i created net work “oracle_net” and mentioned under both the services in docker compose file.The volume “oravolume9” exist.

C:\WINDOWS\System32>docker volume ls
DRIVER VOLUME NAME
local oravolume9

If you start them in the same compose file they automatically share the same network. This is all done by docker-compose, you don’t have to care about it. And then you only have to publish the ports you want to access from outside.

Hi, Thanks for the reply.Could you please clarify one thing. My java application is running in container having ip as “172.18.0.3” and i exposed port as 9088 and 9450 in my docker file. in-order to run the java application i need to execute javaws command as below.
javaws http://172.18.0.3:9088/rtccClient/rtcc.jnlp
when i run this command from my host machine the url is not working. when i logged into container and run the command, it says javaws not found. i created image using “ibmcom/websphere-liberty:latest”. Please update how will i run javaws command

I’m not a Java specialist, so I’m not sure how much I can help.
Don’t investigate the IP addresses of running containers. Containers are ephemeral, so are their addresses. If you just expose ports, this doesn’t have much of an effect. To access a container you have to publish one or more of its ports as you made it with 9088 in the ruleeditor service. Then these ports are attached to your Docker host and you can access them with localhost:$PORTNUMER if you are on the same machine or with $HOST_IP:$PORTNUMBER from outside (replace the variables with the appropriate values).

Hi, Can some one tell what I am doing wrong. My docker container is a Linux container and I created it in windows host machine. So how will I access the application from my windows host machine. I exposed 9088 and 9450 ports in docker file. I started container using run command and forwarded ports as below where 9080 is the port of docker container. The container IP is 172.18.0.3.
“docker run --publish 9088:9080 -d --network oracle_net --name recontainer17 reimage17”.
all below url’s didn’t work
C:\WINDOWS\system32>javaws http://localhost:9088/rtccClient/rtcc.jnlp
C:\WINDOWS\system32>javaws http://localhost:9080/rtccClient/rtcc.jnlp
C:\WINDOWS\system32>javaws http://172.18.0.3:9080/rtccClient/rtcc.jnlp
C:\WINDOWS\system32>javaws http://172.18.0.3:9088/rtccClient/rtcc.jnlp

this is the error i am getting
CouldNotLoadArgumentException[ Could not load file/URL specified: http://172.18.0.3:9080/rtccClient/rtcc.jnlp]

below is my docker file.

FROM ibmcom/websphere-liberty:latest
USER root
ADD ./rtcc.ear /opt/ibm/wlp/usr/servers/defaultServer/apps
ADD ./rtccClient.war /opt/ibm/wlp/usr/servers/defaultServer/apps
RUN yum -y install unixODBC
RUN yum -y install libaio
RUN mkdir -pv /basic
COPY ./basicinstaclient/oracle-instantclient19.8-basic-19.8.0.0.0-1.x86_64.rpm /basic/
RUN rpm -i /basic/oracle-instantclient19.8-basic-19.8.0.0.0-1.x86_64.rpm
EXPOSE 9088
EXPOSE 9450

Websphere in a container? Havyweight JEE servers are lagacy dinosaurs, which technicaly can be containerized, but are usualy a call for trouble. I would even consider Wildfly too heavy for containers, it can be done but is nasty to use. Spring boot applications on the other hand are more suited to be containerized.

This situation kind of reminds me to this: http://turnoff.us/geek/enterprise-vs-startup-journey-to-cloud/

Back to top:
You confuse things. The EXPOSE declaration in the Dockerfile per se does NOTHING except giving a hint on which port the consumer of the image can expect the service to be reachable AND are usefull with linked containers (which I consider a lagacy concept, because links are inferior compared to dsn name resolution in custom networks).

Also you might want to move the two ADD lines to the bottom, otherwise you will not benefit from the build cache if the war/ear files are updated and you want to rebuild the image.

Is there a reason your EXPOSE ports are different than those of the base image, which declares EXPOSE 9080 9443? Just because you declare an EXPOSE does not change the ports the Websphere application server is listing on.

Did you check the container logs and try to access the websphere admin console (last time I used WAS it still had an admin console, though this was 10 years ago) to see if your ear and war are actualy deployed and run without issues?

Hi, if you create a docker n/w using:
$ docker network create --driver overlay --subnet=192.168.0.0/26 --gateway=192.168.0.1 my-network
and then assigning one of the IP from subnet (leave 192.168.0.1)

$ docker run --publish 9088:9088 --net my-network --ip 192.168.0.3 …
which way it will allocate static IP to your container
and try to hit the urls again.

alternatively also try to access urls on docker-host IP (eth0) instead of hitting on localhost and see how it goes.

Hi ,
I changed my docker file. this time i expose the port of docker container and moved the two ADD lines to bottom.you told to run access websphere admin console. since the docker image I created is from “ibmcom/websphere-liberty:latest” i can’t access the admin console after login into container as the linux os inside container is not UI based. When i hit “javaws http://localhost:9080/rtccClient/rtcc.jnlp command from windows host machine below error is coming
CouldNotLoadArgumentException[ Could not load file/URL specified: http://localhost:9080/rtccClient/rtcc.jnlp]

below is my updated docker file
FROM
USER root
RUN yum -y install unixODBC
RUN yum -y install libaio
RUN mkdir -pv /basic
RUN mkdir -pv /resources/security
COPY ./basicinstaclient/oracle-instantclient19.8-basic-19.8.0.0.0-1.x86_64.rpm /basic/
RUN rpm -i /basic/oracle-instantclient19.8-basic-19.8.0.0.0-1.x86_64.rpm
ADD ./rtcc.ear /opt/ibm/wlp/usr/servers/defaultServer/apps
ADD ./rtccClient.war /opt/ibm/wlp/usr/servers/defaultServer/apps
ADD ./resources/bootstrap.properties /opt/ibm/wlp/usr/servers/defaultServer
ADD ./resources/server.xml /opt/ibm/wlp/usr/servers/defaultServer
ADD ./resources/hibernate/ /opt/ibm/wlp/usr/servers/defaultServer/hibernate
ADD ./resources/oracle/ /opt/ibm/wlp/usr/servers/defaultServer/oracle
ADD ./certificates/ /opt/ibm/wlp/usr/servers/defaultServer/resources/security
EXPOSE 9080

This was a suggestion to find out if the deployment are running. I also said to check the container logs and I am kind of missing anything related to that in your repsonse…

You know the drill: make it run, make it right, optimise.
My impression is that you are in the early stages of “make it run”…

Hi,
I deployed rtccClient.war and rtcc.ear and they are running and the websphere liberty profile application server also started. below is captured from logs.I strongly suspect that i can’t access IP or host name from windows machine so only the javaws command is not working. because when i try to ping container IP from host machine it failed
Application rtccClient started in 3.477 seconds.
Application rtcc started in 18.163 seconds.
The defaultServer server is ready to run a smarter planet. The defaultServer server started in 36.823 seconds.