Bobcares

Docker Postgres and PgAdmin | Beginner’s Guide

by | Jul 21, 2022

We can set up and run a fully functional platform in Docker with Postgres and pgAdmin running on the local machine. Read the article to find out more.

In the course of providing Docker hosting support, Bobcares responds to all inquiries, no matter how trivial.

Let’s examine Postgres and pgAdmin in Docker setup by our Support team in more detail.

Postgres And PgAdmin Using Docker

An effective, free, open-source object-relational database management system is PostgreS, also referred to as PostgreSQL. The extensive use of the SQL language in Postgres allows for the scaling and secure storage of even the most complex data workloads. It has been actively developed for more than 30 years, and many businesses and organizations have chosen it for its strong architecture, which has proven to have very high levels of dependability, data integrity, and correctness.

An open source web-based GUI tool called PgAdmin aims to offer a simple way to interact with Postgres databases. PgAdmin uses the Flask framework and is built in Python, jQuery, and Bootstrap. Daily work tasks such as managing databases, tables, columns, relations, indexes, users, permissions, and any other type of database administration operation can carry out via the user interface without losing the ability to execute any SQL statements.

Docker is a software platform that is created to make it easier to develop, distribute, and run applications using containers. It enables programmers to bundle an application with all of the components it requires in a container and send it out as a single package.

Step 1: Getting a Postgres docker container and running it

Docker enables us to download and run containers to run a variety of software programs, so a widely used program like Postgres is not an exception.

  1. Firstly run the command in a terminal to verify the docker installation.

    $ docker version

    The docker installation was successful if we received a message containing the docker details.

  2. Then, using the command below, we can get a Postgres docker image:

    $ docker pull postgres:latest

    Using the previous command, we can download the most recent version of Postgres from a Docker store image. If we want to download a specific version, instead of typing “latest,” we should type “the version we want”

  3. So we can now execute it on a local machine:

    $ docker run --name bobcares-postgres -e POSTGRES_PASSWORD=postgresbobcares -p 5432:5432 -d postgres

  4. Upon successful completion, we could type the following command to view the running container:

    docker ps -a

  5. Finally, we can use the docker exec command to confirm that we have access to the Postgres instance as shown below:

    $ docker exec -it bobcares-postgres bash

Options for the command docker run

Let’s go over the docker run command’s options.

  • We can give our running container a specific name by using the option --name.
  • The container environment variable POSTGRES PASSWORD can be set with the option -e. The image needs this variable to function properly, and it will give the Postgres root password.
  • The -d flag instructs Docker to run the container in “detached” mode in the background. The container runs in the default foreground mode if we don’t use the -d option.
  • Option -p indicates the mapping between the host port and the container port. Because we are using the same port for both in this instance (5432), any requests that are sent to port 5432 on the local host will forward to the same port inside the container.
  • Finally, we must instruct Docker to run the container using the newly downloaded Postgres image.

Step 2: Running a docker container for pgAdmin

The next step is to configure a different container using PgAdmin once the container running Postgres is operational. We can find a list of PgAdmin-related images by performing a quick search for PgAdmin in Docker Hub. In our case, we choose the official Docker distribution of pgAdmin 4 at https://hub.docker.com/r/dpage/pgadmin4.

To get the most recent stable version of the image,

  1. Firstly, run the command in a terminal after opening it.

    $ docker pull dpage/pgadmin4:latest

  2. After downloading the image, we must run the container while ensuring that it connects to the other container that is running Postgres.
  3. Then we enter the command shown below:

    $ docker run --name bobcares-pgadmin -p 82:80 -e <PGADMIN_DEFAULT_EMAIL=bobcares@domain.local> -e <PGADMIN_DEFAULT_PASSWORD=postgres_bobcares_master> -d dpage/pgadmin4

  4. Finally, If all is well, typing the following command should display the running container:

    $ docker ps -a

Let’s go over the docker run command’s options.

  • The descriptions of the parameters --name and -d were in the section before.
  • Using the option -p and the host port number (82) that will forward to the container port number, completes the mapping between the host ports and the container ports (80, where the server with the pgAdmin web app is installed).
  • Finally, we will use the dpage/pgadmin4 image that we just downloaded from Docker Hub because the docker run command needs the image that we use to create the container.

Step 3: Access pgAdmin

  1. Firstly, go to the following website address: http://localhost:8082/ the PgAdmin instance, to enter.docker postgres and pgadmin
  2. As soon as the Postgres container is running, enter the username and password that we created in Step 1.
  3. We need to establish a connection with the Postgres server once we are on the home page.
  4. Simply click Add New Server to start the process, and a new dialogue window will appear.
  5. There are 2 required fields that we must complete:
    1. It is necessary to provide a Name to identify the connection to our Postgres server.
    2. Host name/address is the second necessary value, and it can be found on the form under the Connection tab.
  6. We just need to enter Postgres for the user field and the password used to run Postgres in step one after filling out the host name/address field.
  7. The connection to the Postgres instance will then show up on the left side menu after we click Save.

The Postgres instance running on the container can then be fully managed from there.

[Looking for a solution to another query? We are just a click away.]

Conclusion

In conclusion, Our Support team showed how simple it can be to set up and run the Postgres and pgAdmin platforms using Docker. By obtaining and running the Postgres docker container, running the pgAdmin docker container, and accessing pgAdmin, we completed the task in three simple steps.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.