How to Use the PostgreSQL in Docker in ObjectRocket Instance

Have a Database Problem? Speak with an Expert for Free
Get Started >>

Introduction

PostgreSQL, Docker, and ObjectRocket all help developers get their applications up and running as fast as possible. PostgreSQL is the popular open-source object-relational database many technical professionals rely on to manage their small, medium, and large scale data. Docker containers simplify code development. ObjectRocket allows you to build and manage your applications with performance and scale at the forefront of its technology. When you take a PostgreSQL Docker ObjectRocket approach, you position yourself to get the most out of what they all have to offer. Begin by learning how to how to use PostgreSQL in Docker in ObjectRocket instance. This tutorial shows you how.

Prerequisites

Download and install the following:

>NOTE: Log in or register to try the ObjectRocket Mission Control Panel.

  • PostgresSQL

  • Docker Container

  • Confirm that you have the latest version of PostgreSQL with the psql -V command, version 12.2 or higher.

NOTE: This tutorial about the PostgreSQL Docker ObjectRocket instance method requires general knowledge of how to use the Docker container, PostgreSQL, and the ObjectRocket Mission Control Panel. However, you can always follow along and learn where you need to strengthen your knowledge of any of these applications with these straightforward steps.

Create and Run Docker Container

Docker containers help developers design, build, and share applications fast. When you want reliability in transferring applications to different environments, Docker delivers. Use it to package your application’s executable code including dependencies such as libraries, settings.

Let’s begin to make a Docker container with this code:

1
docker run [OPTIONS] docker_image [COMMAND]{ARGUMENTS}

Here are a few options you should be in this tutorial. The syntaxes used for the PostgreSQL Docker ObjectRocket instance examples are what you’ll use to create a Docker container. Take a few moments to familiarize yourself with them now:

  • Give the Docker container a name by using the option --name

  • Set environment variables detailing how Docker container application with function with the option  -e

  • Publish your Docker container to the PostgreSQL localhost default port 5432 with the option -p

  • When you want to the Docker container in the background, detach it and its ID with the option -d

Use the code below to make the docker container, like this:

1
docker run --name docker_pg -e POSTGRES_PASSWORD=strongpassword -p 4123:4123 -d PostgreSQL

Get the Connection URL of the PostgreSQL in ObjectRocket Instance

Follow these steps to get to your PostgreSQL database from the instance of your ObjectRocket.

  • From the ObjectRocket Mission Control Panel, locate your newly created instance.

  • Click “VIEW MORE DETAILS”.

  • Create a password-protected button for yourself (Admin).

  • Make a copy of the instance by clicking the “CONNECT” tab.

Your code should look similar to this:

1
PostgreSQL://USERNAME:PASSWORD@ingress.hkybrhnz.launchpad.objectrocket.cloud:4123/PostgreSQL?sslmode=require

List the Docker Containers

Display a list of every Docker container for verification of what you’ve created by using this command below:

1
docker ps

Checking the success of what you’ve done reduces the chance of duplicating your work. Here, the results show that you’ve recently created a Docker container. You can even tell the timeframe; the details illustrate that the "docker-entrypoint.s..." shows that the creation of a container was just a few seconds ago.

1
2
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e4ab313c1fa7 PostgreSQL "docker-entrypoint.s…" 13 seconds ago Up 9 seconds 0.0.0.0:4123->4123/tcp, 5432/tcp docker_pg

Access the PostgreSQL Interactive Terminal

  • Get into the interactive terminal in PostgreSQL. In ObjectRocket, run your instance of PostgreSQL with the docker exec command like this:
1
docker exec -it docker_pg psql -U PostgreSQL
  • Next, construct your sample database for the PostgreSQL Docker ObjectRocket instance with this command:
1
CREATE DATABASE demo;

Locate your database from a list. Use the \l to find your Docker container:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
                                 List of databases
   Name    |  Owner   | Encoding |  Collate   |   Ctype    |   Access privileges
   
-----------+----------+----------+------------+------------+--------------------
---
 demo      | PostgreSQL | UTF8     | en_US.utf8 | en_US.utf8 |
 PostgreSQL  | PostgreSQL | UTF8     | en_US.utf8 | en_US.utf8 |
 template0 | PostgreSQL | UTF8     | en_US.utf8 | en_US.utf8 | =c/PostgreSQL        
  +
           |          |          |            |            | PostgreSQL=CTc/postgr
es
 template1 | PostgreSQL | UTF8     | en_US.utf8 | en_US.utf8 | =c/PostgreSQL        
  +
           |          |          |            |            | PostgreSQL=CTc/postgr
es
(4 rows)

Conclusion

Scalability and efficiency. That’s what technical specialists call for when they need to create PostgreSQL Docker ObjectRocket instances seamlessly. The easy steps shown in this tutorial illustrated the simplicity of how you can accomplish that. When you use all three powerful software applications, you release into your hands a triple threat that often exceeds the expectations of today’s powerful local and cloud-based applications.

Pilot the ObjectRocket Platform Free!

Try Fully-Managed CockroachDB, Elasticsearch, MongoDB, PostgreSQL (Beta) or Redis.

Get Started

Keep in the know!

Subscribe to our emails and we’ll let you know what’s going on at ObjectRocket. We hate spam and make it easy to unsubscribe.