PostgreSQL is a free open-source relational database management system. In this article, we will learn basic steps to run the PostgreSQL Docker image.
Step1:
Install And Setup Docker:
Download docker into our local system "https://docs.docker.com/desktop/". Docker was available for all desktop operating systems.
Step2:After downloading the docker installer, then install it. Now to run any docker containers(eg: Redis, MongoDB, PostgreSQL, etc) this docker instance we just installed should be active(should be running).
Postgres Docker Image:
We have to download or pull the Postgres docker image into our local system by running the below command.
docker pull postgres
Run Postgres Docker Container:
After downloading the Postgres image, need to start the container by running the below command.
docker run --name mypostgres -e POSTGRES_PASSWORD=secret -p 5432:5432 -d postgres
- --name flag to specify the name of our container.
- -e flag to specify an environmental variable.
- -p flag to specify the mapping port.
- -d flag to run the command in the background which means detached mode.
Postgres Interaction Terminal:
Since the container up and running we can use the PostgreSQL server. So let's enable the docker interactive terminal for PostgreSQL by running the below command.
docker exec -it mypostgres psql -U postgres
- docker exec -it , this command enables interactive command against the running command
- -U flag to specify the user, the default user is 'postgres'.
Basic Operations In PostgreSQL:
Now let's play with few basic PostgreSQL operations like Database command, table command, insert command, select command, etc.
Command to create the database.
CREATE DATABASE yourdbname;
Command to check the existing databases
\l
Command to create table.
CREATE Table Student(
Id INT PRIMARY KEY NOT NULL,
Name Text NOT NULL);
Command to insert record into the table.
INSERT INTO Student(Id, Name) VALUES(1, 'Naveen');
Command to select records from the table.
select * from Student;
So that's all about a small overview on PostgreSQL using docker.
Video Session:
Support Me!
Buy Me A Coffee
PayPal Me
Wrapping Up:
Hopefully, I think this article delivered some useful information on PostgreSQL using Docker. I love to have your feedback, suggestions, and better techniques in the comment section below.
Comments
Post a Comment