DEV Community

Cover image for Develop over a full database managed service on your laptop!
Javier
Javier

Posted on

Develop over a full database managed service on your laptop!

Do you want to develop your application against a database managed service but you prefer to do it locally? Oracle has recently announced the Oracle Autonomous Database Free Container Image!

In this tutorial we are going to learn how to configure it with Podman, how to access the GUI of the service and how to connect using the MongoDB API! Let's get started!

For this tutorial, I had used an Oracle Linux 8 VM, using the Oracle Cloud free tier:https://www.oracle.com/uk/cloud/free/. Remember you can configure or install it at any place!

As an empty VM, the first thing I did was to install Podman as root:

dnf install podman
Enter fullscreen mode Exit fullscreen mode

Once installed, I had started the container running the following command. The only thing you can change is the PUBLIC_IP. I had used the public IP so I will be able to access from internet without the need of a domain. If you plan to work locally, you can set it to: localhost

podman run -d \
-p 1521:1522 \
-p 1522:1522 \
-p 8443:8443 \
-p 27017:27017 \
--hostname PUBLIC_IP \
--cap-add SYS_ADMIN \
--device /dev/fuse \
--name adb_container \
ghcr.io/oracle/adb-free:latest
Enter fullscreen mode Exit fullscreen mode

For security reasons, you have to change the password. You can run the following command, or you will be asked automatically to change it the first time you connect. It comes with a default password which is Welcome_MY_ATP_1234. I will list all the documentation information at the end of the post.

podman exec adb_container /u01/scripts/change_expired_password.sh MY_ATP admin Welcome_MY_ATP_1234 Oracle_4U123_
Enter fullscreen mode Exit fullscreen mode

Let's open all the ports so we can connect from outside:

firewall-cmd --zone=public --add-port=1522/tcp --permanent
firewall-cmd --zone=public --add-port=8443/tcp --permanent
firewall-cmd --zone=public --add-port=27017/tcp --permanent
firewall-cmd --reload
Enter fullscreen mode Exit fullscreen mode

Now let's connect to the graphical interface. Using the public ip, use the following url: https://public_ip:8443/ords/my_atp/

ordslogin

Is not great? If you go to SQL Developer, and you log in with your ADMIN user, you will be able to access to a great suite of tools! Let me know if you want to know more about this.

dbactions

If you prefer to the database via command line, we need to configure the wallet. For that, we are going to copy it into a local directory.

mkdir /scratch
podman cp adb_container:/u01/app/oracle/wallets/tls_wallet /scratch/tls_wallet
Enter fullscreen mode Exit fullscreen mode

Now we need to set TNS_ADMIN to connect via sqlplus.

export TNS_ADMIN=/scratch/tls_wallet
Enter fullscreen mode Exit fullscreen mode

If you don't have sqlplus, you can install it running the following commands:

dnf install oracle-instantclient-release-el8
dnf install oracle-instantclient-basic
dnf install oracle-instantclient-sqlplus
Enter fullscreen mode Exit fullscreen mode

Finally we can connect via sqlplus directly:

sqlplus admin/Oracle_4U123_@my_atp_low
Enter fullscreen mode Exit fullscreen mode

MongoDB API

One of the great features of the Autonomous Database, is that provides a MongoDB API. With this API, you can connect your MongoDB applications and take all the advantage of an Autonomous Database like: run analytical sql over MongoDB Collections, run machine learning algorithms over JSON data and much more!

We need to identify the connection string. This is displayed during the startup process. We are going to use the podman utility to check the logs of the container:

podman logs adb_container
Enter fullscreen mode Exit fullscreen mode

We are going to be able to find an url like the following:

mongodb://[{user}:{password}@]localhost:27017/{user}?authMechanism=PLAIN&authSource=$external&ssl=true&retryWrites=false&loadBalanced=true
Enter fullscreen mode Exit fullscreen mode

Now that we have the MongoDB Connection string, we are going to install a MongoDB Shell to connect to the Autonomous Database. We are going to download it from the following url:
https://www.mongodb.com/try/download/shell. We are going to download the package and install it:

wget https://downloads.mongodb.com/compass/mongodb-mongosh-2.0.1.x86_64.rpm
rpm -i mongodb-mongosh-2.0.1.x86_64.rpm
Enter fullscreen mode Exit fullscreen mode

Now we can connect with mongosh using the connection string. Remember to set the right user and password to connect.

mongosh 'mongodb://admin:Oracle_4U123_@localhost:27017/admin?authMechanism=PLAIN&authSource=$external&ssl=true&retryWrites=false&loadBalanced=true' --tlsAllowInvalidCertificates
Enter fullscreen mode Exit fullscreen mode

mongosh

That's it! Let me know in the comments if you want to know more about any specific topic. You can find the documentation for the container image here:

You can find all the resources here: oficial documentation:

Top comments (0)