Creating a Docker Container of PostgreSQL
Prerequisites:
- JDK-17 or greater must be installed. To check it open cmd and type java --version C:\Users > java --version java 22.0.2 2024-07-16 Java(TM) SE Runtime Environment (build 22.0.2+9-70) Java HotSpot(TM) 64-Bit Server VM (build 22.0.2+9-70, mixed mode, sharing)
- Download and install Rancher Desktop to enable the docker CLI commands Setup Rancher Desktop - OHP(PP1)-Telikós - Confluence (atlassian.net) [Guide for installation]
- Check if Docker is active, after opening Rancher check for the Docker version in the cmd type Docker --version C:\Users>docker --version Docker version 27.1.1-rd, build cdc3063
Pulling the Docker image of PostgreSQL:
-
Go the Docker Hub (and search for the official image of Postgres. postgres - Official Image | Docker Hub
-
open cmd and use the Docker pull command to pull its image. C:\Users\ksh146 > docker pull postgres Using default tag: latest latest: Pulling from library/postgres
-
On your Rancher Desktop check the images tab. An image of postgres would be present.
-
The image has been created. Now create a container by running the docker run command specified in the official docker hub- Postgres image > how to use section.
-
Copy the docker run command and make some modifications for the port mapping. The command should look like this after adding the required port mapping -p:5432:5432 docker run --name some-postgres -p 5432:5432 -e POSTGRES_PASSWORD=mysecretpassword -d postgres
-
After running this the Postgres container is created and can be viewed in Rancher Desktop → Containers or use the cmd and type docker ps to check the status and specifications.
-
Now connect the image with PG_Admin or and DataBase manager. eg: DBeaver