How to Install pgAdmin Web as a Docker Container with NGINX, SSL, and Domain Setup

This tutorial provides a comprehensive guide for setting up pgAdmin Web with Docker, NGINX, and Let’s Encrypt SSL. Here’s a summary of the steps involved:

Prerequisites βœ…

  • A server (Ubuntu 20.04+ recommended) with Docker installed.
  • Root or sudo access.
  • A registered domain name pointed to your server’s public IP.
  • Basic knowledge of terminal commands.
  • Ports 80 and 443 open in your firewall.
  • (Optional) A backup plan for /var/lib/pgadmin.

Step 1: Deploy pgAdmin Docker Container 🚒

Run the pgAdmin container on port 5050 with the following command, replacing the email and password with your desired credentials:

docker run -d -p 5050:80 \
  -e 'PGADMIN_DEFAULT_EMAIL=your-email@example.com' \
  -e 'PGADMIN_DEFAULT_PASSWORD=YourSecurePassword123' \
  -v /var/lib/pgadmin:/var/lib/pgadmin \
  --name pgadmin \
  --restart always \
  dpage/pgadmin4:latest

Step 2: Set Up NGINX Reverse Proxy πŸ”„

2.1 Install NGINX

sudo apt update
sudo apt install nginx

2.2 Configure Reverse Proxy

Create a new NGINX site configuration file:

sudo nano /etc/nginx/sites-available/pgadmin

Add the following content, replacing your-domain.com with your actual domain:

server {
    listen 80;
    server_name your-domain.com;

    location / {
        proxy_pass http://localhost:5050;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

2.3 Enable NGINX Site

Create a symbolic link and restart NGINX:

sudo ln -s /etc/nginx/sites-available/pgadmin /etc/nginx/sites-enabled/
sudo systemctl restart nginx

Step 3: Enable SSL with Certbot πŸ”’

3.1 Install Certbot

sudo apt install certbot python3-certbot-nginx

3.2 Obtain and Configure SSL

Run Certbot, replacing your-domain.com with your domain. Certbot will automatically configure SSL for NGINX.

sudo certbot --nginx -d your-domain.com

Step 4: Configure Domain DNS 🌐

Log in to your domain registrar and update the DNS A record to point your domain to your server’s public IP address:

TypeNameValue
Ayour-domain.comYour-Server-IP

After DNS propagation, verify SSL and access by visiting https://your-domain.com.


Step 5: Update pgAdmin Container πŸš€

To update your pgAdmin container to the latest version:

5.1 Stop and Remove Old Container

docker stop pgadmin
docker rm pgadmin

5.2 Pull Latest Image & Restart

docker pull dpage/pgadmin4:latest
docker run -d -p 5050:80 \
  -e 'PGADMIN_DEFAULT_EMAIL=your-email@example.com' \
  -e 'PGADMIN_DEFAULT_PASSWORD=YourSecurePassword123' \
  -v /var/lib/pgadmin:/var/lib/pgadmin \
  --name pgadmin \
  --restart always \
  dpage/pgadmin4:latest

Conclusion 🎯

You’ve now successfully set up a secure, production-ready pgAdmin web interface, accessible via your custom domain with HTTPS encryption. Remember to keep your Docker containers and SSL certificates updated regularly and back up your pgAdmin data directory.

Do you have any further questions about managing your PostgreSQL databases or enhancing your server setup?

Views: 105

Leave a Comment