How do I check if Oracle is up in Docker?
i'm using wnameless/oracle-xe-11g-r2 and this works for me
version: '3'services: db: image: wnameless/oracle-xe-11g-r2 environment: - ORACLE_ALLOW_REMOTE=true ports: - 49261:1521 volumes: - ./0_init.sql:/docker-entrypoint-initdb.d/0_init.sql healthcheck: test: [ "CMD", "bash", "-c", "echo 'select 1 from dual;' | ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe /u01/app/oracle/product/11.2.0/xe/bin/sqlplus -s USERNAME/PASSWORD@localhost"] # docker inspect --format "{{json .State.Health }}" myproject_db_1 interval: 10s timeout: 10s retries: 60 myservice: image: xxx depends_on: db: condition: service_healthy
You can mimic tnsping in your Java app: How to do oracle TNSPING with java?
If you can't modify the app, tnsping can be called from a bash script - if you have Oracle client installed. If you don't, simply create a simple application from the link above and execute it in a script.
I've finished with a simple check for APEX:
while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' db:8080/apex)" != "302" ]]; do sleep 5; done
302 is used because it redirects /apex to /apex/some_stuff. In my case db is the name of the container with Oracle:
version: '3'services: ... * other containers * ... db: image: some/image ports: - "8383:8080" - "1521:1521"
Hope it helps someone!