I'm using sath89/oracle-12c for automated tests against a oracle db. This works fine, the only problem is that this container takes several minutes to start (~10-15 depending on the hardware). I tried to come up with a healthcheck for this container.
I managed to come up with
status=`su oracle -c "echo -e \"SELECT ACCOUNT_STATUS FROM DBA_USERS WHERE USERNAME = 'ANONYMOUS' AND ACCOUNT_STATUS = 'EXPIRED';\" | /u01/app/oracle/product/12.1.0/xe/bin/sqlplus -S / as sysdba | grep ACCOUNT_STATUS"`; if [ "$status" == "ACCOUNT_STATUS" ]; then true; else false; fi
which returns 0 when the ANONYMOUS
account is unlocked, which is the last step in the entrypoint
script of the image: entrypoint.sh.
I tested this using docker exec -it <containername> bash
.
I am now stuck with converting this horribly long line into a healthcheck command for docker (docker-compose):
version: "2"
services:
db:
image: sath89/oracle-12c:r1
healthcheck:
test: ["CMD", "<command goes here>"]
interval: 10s
timeout: 3s
retries: 3
Any help is appreciated - if you can improve the command itself I'm happy to here. I am aware of "select 1 from dual" as a validation query for Oracle (source), but this reports an operational DB after ~8 minutes but it resets connections a little bit later. I don't want to modify the container itself - if there's an update I just want to be able to pull it from the hub.