How to Set Up PostgreSQL and pgAdmin with Docker: Step-by-Step Tutorial

Опубликовано: 02 Апрель 2026
на канале: German Gerken
12,632
320

In this video, I’ll guide you through the step-by-step process of setting up PostgreSQL and pgAdmin 4 using Docker. Whether you’re a beginner or looking for an efficient way to manage your databases, this tutorial has you covered.

We’ll start by pulling the necessary Docker images, setting up containers for PostgreSQL and pgAdmin, and connecting them. I’ll also demonstrate how to create a database, add a table, and query it both via pgAdmin and directly from the terminal.

By the end of this video, you’ll have a fully functional PostgreSQL and pgAdmin environment ready to handle your projects. Let’s get started!

Commands Used in the Video:

Step 1: Pull PostgreSQL Image
docker pull postgres

Step 2: Run PostgreSQL Container
docker run --name pg-tutorial -e POSTGRES_PASSWORD=mysecurepassword -p 5432:5432 -d postgres

Step 3: Verify PostgreSQL Container is Running
docker ps

Step 4: Pull pgAdmin 4 Image
docker pull dpage/pgadmin4

Step 5: Run pgAdmin 4 Container
docker run --name pgadmin-tutorial -p 5050:80 -e [email protected] -e PGADMIN_DEFAULT_PASSWORD=securepass -d dpage/pgadmin4

Step 6: Find PostgreSQL Container IP Address
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' pg-tutorial

Step 7: Connect to PostgreSQL via Terminal
docker exec -it pg-tutorial psql -U postgres

Step 8: Switch to a Specific Database
\c my_database

Step 9: Query a Table in PostgreSQL
SELECT * FROM users;

Video Highlights:
Install Docker and set up PostgreSQL.
Configure pgAdmin for database management.
Create and manage databases and tables.
Query the database via terminal and GUI.