Introduction
I really like docker tech, this article will show you how to quickly install and connect the PostgreSQL database on Oracle Cloud by using docker.
You can try it out by signing up for a free account on Oracle Cloud.
Create Compute Instance
Important notes: save the ssh keys to the local computer.
After the instance is created, it will be started automatically and we can see the public IP of the instance in the following screen.
Then we can access Oracle Linux 8 via ssh on the local computer, a command like this
sudo ssh -i ssh-key-2022-11-09.key opc@Public IP
Install Docker
We can install Docker after logging into Oracle Linux 8
sudo su
dnf install -y dnf-utils
dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
dnf install -y docker-ce
system enable docker
Start Docker and Create Database
Start Docker service and run the postgres docker.
systemctl start docker
sudo docker run -d -p 5432:5432 --name postgres -e POSTGRES_PASSWORD=postgres postgres
Notes: the POSTGRES_PASSWORD is database password, for demonstration purposes the password here is also “postgres”
Then we can create a database
sudo docker exec -it postgres bash
psql -U postgres
CREATE DATABASE demo
Notes: there is no postgres image locally, so the docker will pull from library/postgres automatically for you.
Oracle Linux Firewall Configuration
open TCP 5432 port, so that we can access the PostgreSQL database from the local computer.
firewall-cmd --zone=public --list-all
firewall-cmd --permanent --zone=public --add-port=5432/tcp
systemctl restart firewalld
firewall-cmd --zone=public --list-all
Oracle Cloud Firewall Configuration
Add the rule to open TCP 5432 port, so that we can access the PostgreSQL database from the local computer.
Connect to Database
Download client tools DBeaver or pgAdmin from the official site.
We can connect to PostgreSQL Database after installing the tools. The host is the public IP of the instance, same as the user/password is postgres
Conclusion
I have many years of experience using the cloud and many of its services are available out of the box, which saves us a lot of time and is not only very convenient but also greatly increases productivity.