Run A Postgres Docker Container on Oracle Cloud Infrastructure
Learn how to run an always free Docker Container on Oracle Cloud Infrastructure

Search for a command to run...
Learn how to run an always free Docker Container on Oracle Cloud Infrastructure

No comments yet. Be the first to comment.
The Technical Articles series covers topics like online safety, authentication, encryption, Docker, API mocking, and cloud infrastructure. It offers practical insights and tutorials to enhance security and development workflows in modern tech.
An Intro to OAuth With a Real World Example
Explore ways to stay safe on the internet and why online security is important.

This article enables you to understand what WebAuthn (Web Authentication) is and how it works

I recently attended a training session with the Auth0 Dev Rel team on a very cool new feature they have added called Auth0 Actions. In this article, I am going to explain what is Auth0 Actions, why to use them, and how to set one up. What are Auth0 A...

Opinions expressed are solely my own and do not express the views or opinions of my employer. Hey Hackers! I'm Rohit Mathew and I'm the Software Development Engineer at McAfee Enterprise. First of all, a huge thank you to the HackerNoon community and...

Intro to Envelope Encryption & Key Management Systems

In this article, I want to show how I quickly ran a Docker container for free on Oracle Cloud Infrastructure. I made use of a a VM in the Always Free Tier of OCI and for a side project setup a dockerised Postgres database.
Oracle offers an Always Free cloud services. You can see the details below:

Note: the workload of a container has to fit in the shape of this always free VM: VM.Standard.E2.1.Micro, 1/8 OCPU, 1 GB RAM and up to 480 Mbps network bandwidth (see docs). The boot volume offers just over 45GB of disk storage. In order for the container to be accessible, the ports mapped on the VM to container also have to be configured in ingress rules in the security list. We need to install Docker ourselves in the VM; it is provisioned with just an Oracle Linux image.
Lets get started
The first thing we ought to do is create a VM. If you've got a cloud tenancy then you probably already know how to create an instance. If you're new to Oracle Cloud then watch the below video and create an "always free" VM by signing up at https://cloud.oracle.com/free:
Note: Most of the details like availability zone, image details, networking options are already pre-filled by Oracle and kept but can be adjusted if you want something specific. I went ahead with the standard settings.
The VM will now be provisioned — as is indicated:

After a little while, the VM is up and running — and has a public IP address assigned to it:

The situation at this point can be visualized as is shown in the below figure:

The VM is associated with a public subnet in a Virtual Cloud Network. The security list(s) for this subnet should be configured with ingress rules that make the required traffic possible to the port(s) that will be mapped to the container image. Open the details page for the public subnet. Click on the security list (or create a new one)

We will run the Postgres container image. The port we will map in the VM to the Postgres container is one we can choose ourselves. Let’s pick 5432 which is the default port for Postgres. we need to configure an ingress rule as below:

Source CIDR is set to 0.0.0.0/0; along with Source Port Range left blank (i.e. All) this means that this rule applies to any client.
At this point, we have a running VM instance with just a Linux Operating System but no Docker. Let’s SSH into the VM using this command:
ssh opc@public-id-address -i private-key-file
Replace the public-id-address with the public IP assigned to the VM. Replace private-key-file with a reference to the file that contains the SSH private key
Now to install Docker, execute these commands:
sudo yum-config-manager --enable ol7_addons
sudo yum install docker-engine -y
sudo systemctl start docker
sudo systemctl enable docker

To run Docker as a non-root user, read these instructions.
With Docker installed, we can now run the Postgres container image.
Run the container image with this command. Don't forget to add a different password for POSTGRES_PASSWORD:
sudo docker run -d -p 5432:5432 --name postgres -e POSTGRES_PASSWORD=mysecretpassword postgres
Use sudo docker ps to verify if the container is running. The above command will start a PostgreSQL database and map ports using the following pattern: -p <host_port>:<container_port>. Port 5432 of our container will be mapped on port 5432 of our host or server.
Access the container on your host or server. We will create a database inside our Postgres container.
sudo docker exec -it postgres bash
Now you are ‘inside’ your container. We can access postgres and create the database.
root@12d48fde2627:/# psql -U postgres
psql (13.3 (Debian 13.3-1.pgdg100+1))
Type "help" for help.
postgres=# CREATE DATABASE testdb;
CREATE DATABASE
postgres=# \q
We are finished. You can exit your container (\q) and go to your local machine. Here you need some PostgreSQL Client tool installed like DBeaver or pgAdmin. Connect to the DB server by using the public IP as the host, 5432 as the port, postgres as the username, the POSTGRES_PASSWORD as the password and connect to the testdb. Save the connect and you should now be able to access your DB.
Thanks for reading! I really hope that you find this article useful. I invite you to participate in the discussion in the comments below, I'm always interested to know your thoughts and happy to answer any questions you might have in your mind. If you think this post was useful, please like the post to help promote this piece to others.
Thanks for reading! :)
P.S Do feel free to connect with me on LinkedIn or Twitter
This article leans heavily on the following material:
Run Always Free Docker Container on Oracle Cloud Infrastructure - Lucas Jellema
Connect From Your Local Machine to a PostgreSQL Database in Docker - Lorenz Vanthillo