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

In this tutorial, we will walk you through setting up pgAdmin Web as a Docker container, with NGINX as a reverse proxy, SSL encryption using Certbot, and a custom domain. Follow the steps below to complete your setup. πŸ–₯οΈπŸ”

Step 1: Run pgAdmin in a Docker Container 🚒

To get started, we will run the pgAdmin container using the following Docker command. This will start pgAdmin on port 5050 and set the default credentials. πŸ”‘πŸ“§

docker run -d -p 5050:80 \
  -e '[email protected]' \
  -e 'PGADMIN_DEFAULT_PASSWORD=YourSecurePassword123' \
  -v /var/lib/pgadmin:/var/lib/pgadmin \
  --name pgadmin \
  --restart always \
  dpage/pgadmin4:latest

In the command above, replace [email protected] and YourSecurePassword123 with your desired pgAdmin credentials. πŸ› οΈ

Step 2: Install NGINX for Reverse Proxy πŸ”„

Next, we will install NGINX to act as a reverse proxy for the pgAdmin container. This will allow you to access pgAdmin using your domain name. 🌐

1. Install NGINX 🧰

sudo apt update
sudo apt install nginx

2. Configure NGINX βš™οΈ

Create a new NGINX site configuration file for pgAdmin:

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

Inside the file, add the following configuration:

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;
    }
}

Make sure to replace your-domain.com with your actual domain name. 🌍

3. Enable NGINX Configuration βœ…

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

Step 3: Install SSL with Certbot πŸ”’

Now, we’ll install Certbot to obtain an SSL certificate for securing your connection to pgAdmin using HTTPS. πŸ”‘πŸ›‘οΈ

1. Install Certbot πŸ§‘β€πŸ’»

sudo apt install certbot python3-certbot-nginx

2. Obtain SSL Certificate 🧳

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

Replace your-domain.com with your actual domain. Certbot will automatically configure NGINX with SSL settings for your domain. πŸ”

Step 4: Set Up Domain for Access 🌐

Now, it’s time to set up your domain to point to the server’s IP address. πŸ–₯️

  1. Go to your domain registrar’s website (e.g., GoDaddy, Namecheap). πŸ“

  2. Update your DNS settings to point to your server’s IP address:

Type Name Value
A your-domain.com Your-Server-IP

Replace Your-Server-IP with the actual IP address of your server. πŸŒπŸ“Ά

2. Verify SSL βœ…

Once the DNS records have propagated, visit https://your-domain.com to verify that SSL is correctly installed and that pgAdmin is accessible. πŸ”’

Step 5: Update pgAdmin πŸš€

To keep your pgAdmin instance up-to-date, you will need to update the Docker container periodically. Here’s how to do it: πŸ”„

1. Stop the Running Container πŸ›‘

Before updating, stop the existing pgAdmin container:

docker stop pgadmin

2. Remove the Old Container πŸ—‘οΈ

After stopping the container, remove it to free up resources:

docker rm pgadmin

3. Pull the Latest pgAdmin Image πŸ”„

Next, pull the latest version of the pgAdmin image:

docker pull dpage/pgadmin4:latest

4. Recreate the pgAdmin Container πŸ› οΈ

Finally, recreate the container using the same parameters as before:

docker run -d -p 5050:80 \
  -e '[email protected]' \
  -e 'PGADMIN_DEFAULT_PASSWORD=YourSecurePassword123' \
  -v /var/lib/pgadmin:/var/lib/pgadmin \
  --name pgadmin \
  --restart always \
  dpage/pgadmin4:latest

After running the command, pgAdmin will be updated to the latest version. πŸŽ‰

Conclusion 🏁

You have now successfully set up pgAdmin as a Docker container, secured with SSL using Certbot, and accessed through a custom domain via NGINX. You also now know how to update your pgAdmin container regularly to ensure you have the latest features and security patches. πŸŽ‰

Leave a Reply