NOTE: If docker is not installed in your machine first do that before following next.
Official Docker Image: https://hub.docker.com/_/postgres
docker run -d \
--name postgres-db \
-p 5432:5432 \
-e POSTGRES_USER=myuser \
-e POSTGRES_PASSWORD=mypassword \
-e POSTGRES_DB=mydb \
postgresOfficial Docker Image: https://hub.docker.com/r/dpage/pgadmin4
docker run -d \
--name pgadmin \
-p 5050:80 \
-e PGADMIN_DEFAULT_EMAIL=admin@admin.com \
-e PGADMIN_DEFAULT_PASSWORD=secret \
dpage/pgadmin4Now you have SQL server and PGAdmin UI both are running we can connect them together.
Go on the localhost:5050 and login with your provided email and password. In this case
Email: admin@admin.com
Password: secret
Connect your SQL server with the credentials you used in step 01 to run the PostgreSQL server
UserName: myuser
Password: mypassword
We have not specified the common network for PostgreSQL Server and PGAdmin while running from Docker. So they can't talk each directly. Hence when you are connecting the Server from PGAdmin use
Domain/Host: host.docker.internal
Port: 5432
That's it this should connect our SQL server and Admin together.
If we wish to run both container in same network then we can create a network and specify it while running their docker commands as:
Create a network:
docker network create pg-networkRun PostgresSQL Server specifying the network.
docker run -d \
--name postgres-db \
--network pg-network \
-e POSTGRES_USER=myuser \
-e POSTGRES_PASSWORD=mypassword \
-e POSTGRES_DB=mydb \
-p 5432:5432 \
postgresRun PGAdmin Container specifying the network.
docker run -d \
--name pgadmin \
--network pg-network \
-p 5050:80 \
-e PGADMIN_DEFAULT_EMAIL=admin@admin.com \
-e PGADMIN_DEFAULT_PASSWORD=secret \
dpage/pgadmin4Go to the localhost:5050 and now login with your specified credentials.
This time you can give:
HostName/Address: postgres-db (Which is the name of your PostgresSQL server)
- Pull the Container Image
docker pull dpage/pgadmin4- Create the Container Configures and create the container without starting it immediately.
docker create \
--name pgadmin \
-p 5050:80 \
-e PGADMIN_DEFAULT_EMAIL=admin@admin.com \
-e PGADMIN_DEFAULT_PASSWORD=secret \
dpage/pgadmin4- Start the Container
docker start pgadmin- Check status
docker ps -f name=pgadmin