Deploy a powerful, open-source PostgreSQL database on Ubuntu with Docker. The script auto-generates secure credentials and displays connection details at the end.
Grab the automated bash script from GitHub to follow along with the video.
wget https://raw.githubusercontent.com/mhmdali94/Docker/main/databases/postgres/postgres-ubuntu.sh
chmod +x postgres-ubuntu.sh
sudo bash postgres-ubuntu.sh
The script installs Docker, generates a secure random password, and starts PostgreSQL with a ready-to-use database and user.
wget https://raw.githubusercontent.com/mhmdali94/Docker/main/databases/postgres/postgres-ubuntu.sh
chmod +x postgres-ubuntu.sh
sudo bash postgres-ubuntu.sh
The script displays the generated credentials at the end. Save them immediately:
| Field | Value |
|---|---|
| User | pgadmin |
| Database | pgdb |
| Password | auto-generated — shown at end of script |
| Port | 5432 |
psql -h <server-ip> -U pgadmin -d pgdb
-- Check connection
SELECT version();
-- Create a test table
CREATE TABLE test (id SERIAL PRIMARY KEY, name TEXT);
INSERT INTO test (name) VALUES ('Hello, PostgreSQL!');
SELECT * FROM test;
| Port | Purpose |
|---|---|
| 5432 | PostgreSQL |