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. π₯οΈ
- Go to your domain registrar’s website (e.g., GoDaddy, Namecheap). π
- 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. π