If you are using multiple containers to set up your Oracle Development (or Test or Production) environment - as I described here - you probably ran into the issue that your ORDS container was started before the Database was started up. This results in an ORDS container that is not working - at least not as you need to.
So how do we tell the ORDS to configure itself in one container to wait for the database in another container is ready to use?
This port will become available when the database is up and running.
Step 2:
Get the "wait-for-it" shell script from https://github.com/vishnubob/wait-for-it. In your ORDS Dockerfile copy this in the root of your container and change the Entrypoint from just /config_ords_and_run_catalina.sh to a call to /wait-for-it.sh specifying the Oracle port from step 1. You don't need to use port forwarding as both containers run on the same Docker network and can access each others ports. The example below will wait for max 2 minutes for the Oracle database to start up (if it isn't ready, the rest of the script will not run as it won't make any sense).
After recreating the image with these changes to the Dockerfile and using Docker Compose to start it all up, the logging of the ORDS container will show the following before proceeding with the configuration:
Using Docker Compose you can specify a depends_on option, for instance in the ORDS container configuration you specify (where "oracle" refers to the container that holds the Oracle database) :
depends_on :
- oracle
but this only means the ORDS container will start after the "oracle" container has been started. That does not mean the Oracle database inside the container is started and available!So how do we tell the ORDS to configure itself in one container to wait for the database in another container is ready to use?
Step 1:
Start the Oracle database (container), connect to it and enable a port - in this example 8080 - in the Oracle database
begin
dbms_xdb_config.sethttpport( 8080 );
end;
/
Step 2:
Get the "wait-for-it" shell script from https://github.com/vishnubob/wait-for-it. In your ORDS Dockerfile copy this in the root of your container and change the Entrypoint from just /config_ords_and_run_catalina.sh to a call to /wait-for-it.sh specifying the Oracle port from step 1. You don't need to use port forwarding as both containers run on the same Docker network and can access each others ports. The example below will wait for max 2 minutes for the Oracle database to start up (if it isn't ready, the rest of the script will not run as it won't make any sense).
COPY ./wait-for-it.sh /
RUN chmod +x /*.sh
ENTRYPOINT ["/wait-for-it.sh","oracle:8080","--timeout=120","-s","--","/config_ords_and_run_catalina.sh"]
wait-for-it.sh: waiting 120 seconds for oracle:8080
wait-for-it.sh: oracle:8080 is available after 42 seconds
wait-for-it.sh: oracle:8080 is available after 42 seconds
And that is exactly what we want! Now we defined a proper dependency between our database to be available and our ORDS service.
Note: This will only work properly if your database is already created. If you want this to work when the database has to be created first, you need to add step 1 into your database creation script and need to set the timeout parameter in step 3 to a higher value.
Note: This will only work properly if your database is already created. If you want this to work when the database has to be created first, you need to add step 1 into your database creation script and need to set the timeout parameter in step 3 to a higher value.
Comments