The latest version of pgAdmin, version 4, is not available in the Ubuntu repo’s. To install you need to install Python, set up an virtual environment, etc. It’s a lot easier to run pgAdmin from a Docker container. In this post I will explain how to set this up and create a secure ssh tunnel to your PostgreSQL database from the container.
Install Docker with this simple script:
sudo curl -sSL https://get.docker.com/ | sh
Start the Docker service:
sudo service docker start
Download and start the pgAdmin container:
docker run -d -p 5050:5050 -v data:/home/pgadmin –name pgadmin nphung/pgadmin
Now open your browser and navigate to http://127.0.0.1:5050. You should see something like this:
The safest way to connect to your database is to use ssh. You don’t need to open up any additional ports this way. Issue the following command on your local computer:
ssh -fNg -L 172.16.1.2:5432:localhost:5432 188.8.131.52
The fist IP adres and port (172.16.1.2:5432) is the IP of your local computer. In your case it will be different, use the command ip addr to look it up. The port 5432 is the port you will be connecting to.
The second IP and port is the address of your PostgreSQL database server.
Now go to your browser and right-click on Servers, Create”, Server”.
Enter a name in the General tab. Enter IP address, User name and Password and press Save:
Now right-click on the entry you just made and click Connect Server. You should now be connected to your database server.