To set up pgAdmin4 with Docker, follow these steps:
-
Install the required dependencies:
sudo apt install apt-transport-https ca-certificates curl software-properties-common
-
Import the Docker GPG key and add the Docker repository:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null sudo apt update
-
Install and check Docker:
sudo apt install docker-ce sudo systemctl status docker sudo usermod -aG docker ${USER} exit
-
Verify Docker installation and test with a sample container:
docker info docker run hello-world
-
Install Docker Compose:
sudo apt install docker-compose
-
Create a directory for the pgAdmin4 setup:
mkdir ~/pgadmin cd ~/pgadmin/
-
Create a
docker-compose.yml
file and add the following content:version: '3' services: pgadmin: container_name: pgadmin4_container image: dpage/pgadmin4 restart: always environment: PGADMIN_DEFAULT_EMAIL: ###ADMIN_EMAIL### PGADMIN_DEFAULT_PASSWORD: ###STRONG_PASSWORD### ports: - "5050:80" extra_hosts: - "host.docker.internal:host-gateway"
-
Update PostgreSQL configuration:
-
Open
postgresql.conf
and set (sudo vi /etc/postgresql/14/main/postgresql.conf
)listen_addresses = '*'
-
Open
pg_hba.conf
and add (sudo vi /etc/postgresql/14/main/pg_hba.conf
):host all all 172.0.0.0/8 md5
-
Restart PostgreSQL:
sudo service postgresql restart
-
-
Start pgAdmin4 container:
docker compose up -d
-
Verify pgAdmin4 is running:
curl localhost:5050
-
Make sure you have the necessary Apache modules enabled. Run the following commands on your Docker host:
sudo a2enmod proxy sudo a2enmod proxy_http sudo a2enmod ssl sudo ufw allow 5430 sudo ufw allow 5432
-
Add a VitualHost to apache
pgadmin4.conf
(sudo vi /etc/apache2/sites-available/pgadmin4.conf
)Listen 5430 <VirtualHost *:5430> ServerName pro.24-7jobs.com SSLEngine on SSLCertificateFile /etc/apache2/ssl/server.crt SSLCertificateKeyFile /etc/apache2/ssl/server.key # SSLCertificateChainFile /etc/apache2/ssl/server-ca.crt ProxyPass / http://localhost:5050/ ProxyPassReverse / http://localhost:5050/ </VirtualHost>
-
Enable VirtualHost
sudo rm -r /etc/apache2/conf-available/pgadmin4.conf sudo rm -r /etc/apache2/conf-enabled/pgadmin4.conf sudo a2disconf pgadmin4.conf sudo a2ensite pgadmin4.conf
-
Restart Apache to apply the changes. Run the following command to restart Apache:
sudo service apache2 restart
-
If on AWS, expose port 5430 in security group and restrict access.
That's it! Your pgAdmin4 setup with Docker is complete.
Here is the bash script for the same