Connecting To Oracle Database

From Alpine Linux

Connecting to a Oracle database directly does not seem to be possible due to the driver being compiled for GNU libc and it being proprietary. It is possible to connect to one database using Docker however. The image is proprietary as well, so a docker login is required and the "Proceed to Checkout" on https://hub.docker.com/_/oracle-instant-client has to be went through.

Create the environment

First, create the container and mount the current directory:

docker run --name okcli -v ${PWD}:/data -d -e LC_CTYPE=en_US.UTF-8 store/oracle/database-instantclient:12.2.0.1 sh -c "yum update -y && yum install -y python3-pip util-linux vim && pip3 install okcli && tail -f /dev/null"

You may check if the installation has finished by running:

docker logs -f okcli

Now, whenever you need to connect to a database, run the following:

docker restart okcli && docker exec -it okcli sh -c "cd /data && sh"

Option 1: Connecting with with okcli

okcli is a libre CLI to access a Oracle database. You can connect using it by now entering the following command in the prompt from above:

okcli 'myusername/mypassword@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=141.62.75.20)(Port=1521))(CONNECT_DATA=(SID=DB1)))'

You can run a script in the directory you've mounted above like so:

okcli 'myusername/mypassword@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=141.62.75.20)(Port=1521))(CONNECT_DATA=(SID=DB1)))' -@ myscript.sql

Option 2: Connecting with with SQL Plus

SQL Plus is the proprietary CLI to access a Oracle database. You can connect using it by now entering the following command in the prompt from above:

sqlplus 'myusername/mypassword@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=141.62.75.20)(Port=1521))(CONNECT_DATA=(SID=DB1)))'

You can run a script in the directory you've mounted above like so:

sqlplus 'myusername/mypassword@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=141.62.75.20)(Port=1521))(CONNECT_DATA=(SID=DB1)))' @myscript.sql