Skip to content

Instantly share code, notes, and snippets.

@rambabu-patidar
Last active August 29, 2026 14:06
Show Gist options
  • Select an option

  • Save rambabu-patidar/ad3b43ac81c59b7564afb4225cfa0a2e to your computer and use it in GitHub Desktop.

Select an option

Save rambabu-patidar/ad3b43ac81c59b7564afb4225cfa0a2e to your computer and use it in GitHub Desktop.
This quick gist shows how we can start the PostgreSQL Server with PGAdmin UI in Docker.

Docker Installation of PostgreSQL with PGAdmin UI for quick Setup

NOTE: If docker is not installed in your machine first do that before following next.

Step 01 (Run the Database Server Container)

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 \
  postgres

Step 02 (Run the PGAdmin UI Container)

Official 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/pgadmin4

Now you have SQL server and PGAdmin UI both are running we can connect them together.

Step 03

Go on the localhost:5050 and login with your provided email and password. In this case

Email: admin@admin.com

Password: secret

Step 04

Connect your SQL server with the credentials you used in step 01 to run the PostgreSQL server

UserName: myuser

Password: mypassword

IMPORTANT

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.

EXTRA:

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-network

Run 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 \
  postgres

Run 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/pgadmin4

Go 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)

MORE EXTRA For Learning.

MultiStep(for Step 02) for understading and Learning

  1. Pull the Container Image
docker pull dpage/pgadmin4
  1. 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
  1. Start the Container
docker start pgadmin
  1. Check status
docker ps -f name=pgadmin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment