author avatar

soniya.rayabagi

Thu Feb 22 2024

Create a PostgreSQL Database in Docker .

Step 1: Download the latest version of the Postgres image :

 docker pull postgres

Step 2: Create and Run Postgres Container :

docker run -d --name <container_name> -p 5432:5432 -e POSTGRES_PASSWORD=<password> postgres

Step 3: Verify Executing Container :

docker ps

Step 4: Interact with Executing Container :

docker exec -it <container_name> bash

Step 5: Connect to Postgresql Database Server :

psql -h localhost -U postgres

Step 6: Create Postgresql Database :

CREATE DATABASE <database_name>;
\l

Step 7: Establish a connection with database :

\c <database_name>

Step 8: Create Database User :

CREATE USER <user_name> with PASSWORD <password>;

Step 9: Exit :

 \q

#devops #docker