
Installing, running, and managing postgres in a local machine for application development is not difficult anymore. There is a simple way to get started with the installation and configuration right away using Docker. Through Docker, you can skip all the complex installation steps otherwise required for using PSQL in local development. You can now kick-start the development of postgres based applications in just a few seconds.
To get started, follow these steps:
Run the following command in Linux, Windows, or Mac machines from the terminal or command-prompt to pull PSQL from docker-hub.
docker run --name postgresql-container -p 5432:5432 -e POSTGRES_PASSWORD=somePassword -d postgres
In the above command replace
You will be able to see a new container created and running at 0.0.0.0:5432. To verify, use the command:
docker ps -a

The postgres server is now running in the IP of your local machine. The PostgresQL server is now ready to use for development.
Download the pgAdmin-4 browser version from docker-hub using the following command.
docker run --rm -p 5050:5050 thajeztah/pgadmin4
Now manage your postgres server from the browser by launching http://localhost:5050.


Enter the credentials to save and manage PSQL via GUI.
Host - The IP address of your machine
Password - Password used while creating the PSQL server with docker

The steps below are to connect to the psql server from CLI

(example: JavaScript)
const { Client } = require('pg');
let client = new Client({
connectionString: "postgresql://postgres:test1234@192.168.225.86:5432/postgres"
});
const connectDB = async () => {
try {
console.log('Connect to Postgres ...');
client.connect();
await new Promise((resol, rej) => {
client.query('Select now() as run_at;', (err, res) => {
if(err) {
console.log(err);
reject(err);
} else {
console.log(`Run at date-time : ${res.rows[0].run_at}`);
resol(res.rows[0].run_at);
}
})
});
await client.end();
console.log('Execution Completed ...');
} catch (err) {
console.log('Error while Connecting DB !')
}
}
connectDB();
Please note that these steps simplify the development process. You may choose to follow the conventional method of installing PSQL separately for the production environment if you prefer to.
About Ideas2IT:
Are you looking to build a great product or service? Do you foresee technical challenges? If you answered yes to the above questions, then you must talk to us. We are a world-class Custom dot net development company. We take up projects that are in our area of expertise. We know what we are good at and more importantly what we are not. We carefully choose projects where we strongly believe that we can add value. And not just in engineering but also in terms of how well we understand the domain. Book a free consultation with us today. Let’s work together.

