↑ Up | ← Previous | Next →
pgcli is a handy tool but it's cumbersome to use for complex queries and database management. pgAdmin is a web-based tool that makes it more convenient to access and manage our databases.
It's possible to run pgAdmin as a container along with the Postgres container, but both containers will have to be in the same virtual network so that they can find each other.
docker run -it \
-e PGADMIN_DEFAULT_EMAIL="admin@admin.com" \
-e PGADMIN_DEFAULT_PASSWORD="root" \
-v pgadmin_data:/var/lib/pgadmin \
-p 8085:80 \
dpage/pgadmin4The -v pgadmin_data:/var/lib/pgadmin volume mapping saves pgAdmin settings (server connections, preferences) so you don't have to reconfigure it every time you restart the container.
- The container needs 2 environment variables: a login email and a password. We use
admin@admin.comandrootin this example. - pgAdmin is a web app and its default port is 80; we map it to 8085 in our localhost to avoid any possible conflicts.
- The actual image name is
dpage/pgadmin4.
Note: This won't work yet because pgAdmin can't see the PostgreSQL container. They need to be on the same Docker network!
Let's create a virtual Docker network called pg-network:
docker network create pg-networkYou can remove the network later with the command
docker network rm pg-network. You can look at the existing networks withdocker network ls.
Stop both containers and re-run them with the network configuration:
# Run PostgreSQL on the network
docker run -it \
-e POSTGRES_USER="root" \
-e POSTGRES_PASSWORD="root" \
-e POSTGRES_DB="ny_taxi" \
-v ny_taxi_postgres_data:/var/lib/postgresql \
-p 5432:5432 \
--network=pg-network \
--name pgdatabase \
postgres:18
# In another terminal, run pgAdmin on the same network
docker run -it \
-e PGADMIN_DEFAULT_EMAIL="admin@admin.com" \
-e PGADMIN_DEFAULT_PASSWORD="root" \
-v pgadmin_data:/var/lib/pgadmin \
-p 8085:80 \
--network=pg-network \
--name pgadmin \
dpage/pgadmin4- Just like with the Postgres container, we specify a network and a name for pgAdmin.
- The container names (
pgdatabaseandpgadmin) allow the containers to find each other within the network.
You should now be able to load pgAdmin on a web browser by browsing to http://localhost:8085. Use the same email and password you used for running the container to log in.
- Open browser and go to
http://localhost:8085 - Login with email:
admin@admin.com, password:root - Right-click "Servers" → Register → Server
- Configure:
- General tab: Name:
Local Docker - Connection tab:
- Host:
pgdatabase(the container name) - Port:
5432 - Username:
root - Password:
root
- Host:
- General tab: Name:
- Save
Now you can explore the database using the pgAdmin interface!
↑ Up | ← Previous | Next →