Postgres connection with docker

Postgres connection with docker

Steps to create a docker container of postgres image:-

  1. Start PowerShell.

  2. Download the Postgres docker image.

  3. Start the docker container in detached mode with the name postgres-0 specify port -p as 5432 and POSTGRES_PASSWORD as the password.

  4. Check the status of running containers

  5. Go inside container_name in interactive mode.

docker pull postgres #download image
docker run --name postgres-0 -e POSTGRES_PASSWORD=password -d -p 5432:5432 postgres

docker ps ##show running container
docker exec  -it postgres-0 bash
ls
psql --help
\du  ##role name i.e. super user
create database test;

\l ##list of databases

Create sample data.

CREATE DATABASE test;
\c test
CREATE TABLE test_table(something int);
INSERT INTO test_table VALUES (123);
SELECT * FROM test_table;
\q