One of the most important phases of the Software Development Life Cycle (SDLC) is Data Processing. This involves actions like Data Joining, Data Cleaning, Data Filtering, and more. Usually, developers use Database Management Applications like MySQL and PostgreSQL to implement Data Processing Operations. Besides, while developing such applications, developers work with several temporary software that gets employed at different phases of their SDLC.
To run different applications and processes, developers use Docker as a containerization platform. It omits the need to install and run applications in different environments. Developers can perform Data Processing Operations using any Database Management System (DBMS) like PostgreSQL by pulling in their respective Docker Image files from the Docker Hub.
In this blog, you will learn about the process of setting up a Docker PostgreSQL environment. We’ll show how you can install, configure, and run PostgreSQL on Docker in 3 simple steps. Read on to get started.
Table of Contents
Prerequisites for Setting Up Docker PostgreSQL Environment
A fundamental understanding of Data Processing Operations and Database Management Systems (DBMS) like PostgreSQL.
What is Docker?
Developed by Solomon Hykes in 2013, Docker is an Open-Source software tool that allows you to quickly build, test, manage, and deploy applications. It carries multiple containers that comprise all executable packages and dependencies required to run an application. Docker Containers are built using Docker Images, a template that comprises all the parameters and instructions required to run a particular application.
You can access different Docker Containers by signing up on an online cloud repository called Docker Hub. From the Docker Hub, you can easily pull or download pre-configured Docker Containers, like Docker PostgreSQL Container to execute specific applications based on your requirements.
If you are a software developer, you can also upload and share your own applications in the form of Docker images that can be used by other Docker users to try and execute your application.
Hevo Data, a No-code Data Pipeline, helps load data from any Data Source such as Databases, SaaS applications, Cloud Storage, SDKs, and Streaming Services, and simplifies the ETL process. It supports 150+ Data Sources including 40+ Free Sources. It is a 3-step process just selecting the data source, providing valid credentials, and choosing the destination. Hevo loads the data onto the desired Data Warehouse/Destination like Google BigQuery, Snowflake, Amazon Redshift, and Firebolt and enriches the data transforming it into an analysis-ready form without having to write a single line of code.
It’s a completely Automated Pipeline that offers data to be delivered in real-time without any loss from Source to Destination. Its fault-tolerant and scalable architecture ensure that the data is handled in a secure, consistent manner with zero data loss and supports different forms of data. The solutions provided are consistent and work with different BI Tools as well.
Get Started with Hevo for Free
Check out why Hevo is the best:
- Minimal Learning: Hevo, with its simple and interactive UI, is extremely simple for new customers to work on and perform operations.
- Hevo Is Built To Scale: As the number of sources and the volume of your data grows, Hevo scales horizontally, handling millions of records per minute with very little latency.
- Secure: Hevo has a fault-tolerant architecture that ensures that the data is handled securely and consistently with zero data loss.
- Schema Management: Hevo takes away the tedious task of schema management & automatically detects the schema of incoming data and maps it to the destination schema.
- Incremental Data Load: Hevo allows the transfer of data that has been modified in real-time. This ensures efficient utilization of bandwidth on both ends.
- Live Support: Our team is available round the clock to extend exceptional support to its customers through Chat, Email, and Support Calls.
- Live Monitoring: Hevo allows you to monitor the data flow and check where your data is at a particular point in time.
Sign up here for a 14-Day Free Trial!
What are the 3 Steps to set up Docker PostgreSQL Environment
In the sections below, we show you a step-by-step process to install, set up, and run Docker PostgreSQL Environment.
Step 1: Download and Install Docker
Image Source: Self
Before starting the application setup process for Docker PostgreSQL Environment, you are required to download and install Docker on your local machine. To download the application, visit the official website of Docker. On the welcome page of the Docker website, click on the “Get-Started” option. You will be redirected to the download page, where you can download the Docker version according to your operating system specifications.
Select the preferred option to start the downloading process. After the Docker setup file is downloaded, install it on your local machine by following the installation steps.
Image Source: Self
Next, you can sign in on Docker Hub, from where you can access the Docker Image files. This will be used to run external applications like PostgreSQL.
Step 2: Download the Docker PostgreSQL Image
There are two different ways to download the Docker PostgreSQL Image that allows you to set up PostgreSQL on Docker. One is by directly accessing it from the Docker Hub’s website. The other method is by pulling the Docker PostgreSQL Image from default Command Line Interface (CLI) tools like Command Prompt or Power Shell.
If you are opting for method one:
- To download the Docker PostgreSQL Image, visit Docker Hub using your previously created user account.
- On the welcome page, you can find a search bar at the top. Type “PostgreSQL” to get the Docker Image of the respective application. You can find various Docker Images related to the PostgreSQL database.
On clicking on the appropriate file, you will be redirected to a new page where you can find the command used to access the Docker Image file. Copy and make a note of the respective command. Run this into your Command Prompt to install the PostgreSQL instance.
Another way to pull Docker PostgreSQL Image is by accessing it using the Command Prompt instead of reaching its website. To do so, follow these steps:
- Open a new command window, and run the command given below.
docker pull postgres
- To obtain the list of existing Docker Images, run the following command.
docker images
- In the next step, you can enter the command you copied from the Docker Hub in the Command Prompt.
docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres
- The above-given command should be customized and added with the necessary parameters to work properly for setting up PostgreSQL on Docker.
docker run --name postgresql -e POSTGRES_USER=myusername -e POSTGRES_PASSWORD=mypassword -p 5432:5432 -v /data:/var/lib/postgresql/data -d postgres
In the command given above,
- PostgreSQL is the name of the Docker Container.
- -e POSTGRES_USER is the parameter that sets a unique username to the Postgres database.
- -e POSTGRES_PASSWORD is the parameter that allows you to set the password of the Postgres database.
- -p 5432:5432 is the parameter that establishes a connection between the Host Port and Docker Container Port. In this case, both ports are given as 5432, which indicates requests sent to the Host Ports will automatically redirect to the Docker Container Port. In addition, 5432 is also the same port where PostgreSQL will be accepting requests from the client.
- -v is the parameter that synchronizes the Postgres data with the local folder. This ensures that Postgres data will be safely present within the Home Directory even if the Docker Container is terminated.
- -d is the parameter that runs the Docker Container in the detached mode, i.e., in the background. If you accidentally close or terminate the Command Prompt, the Docker Container will still run in the background.
- Postgres is the name of the Docker image that was previously downloaded to run the Docker Container.
Now, execute docker ps -a to check the status of the newly created PostgreSQL container.
Image Source
On executing the command, you get the output, as shown in the above image. It shows that Docker Container is running successfully on port 5432. You can start and stop the newly created Docker Container by running the following commands.
- For starting the Docker Container:
docker start postgresqldb
- For stopping the Docker Container:
docker stop postgresqldb
There you have it. You have now successfully created a Docker Container running the PostgreSQL Environment.
Step 3: Install PGAdmin on Docker
At this stage of setting up the Docker PostgreSQL Environment, your PostgreSQL is active and running on the respective ports. Now, you have to install PGAdmin, a web-based GUI tool used to manage PostgreSQL databases and services. You can install PGAdmin to check whether your Docker Containers are working fine and execute SQL queries on databases present in PostgreSQL.
To download PGADmin, perform these steps:
- Visit Docker Hub and search for PgAdmin. You can find various Docker Images to run PGAdmin. Select the appropriate one and copy the Docker pull command (Follow this link to get the “Docker pull” command, which pulls the PGAdmin4 version. You can also get the respective PGAdmin versions according to your preferences).
- Execute the pull command to start PGAdmin.
docker pull dpage/pgadmin4:latest
- After downloading the image, run the container by executing the command given below.
docker run --name my-pgadmin -p 82:80 -e 'PGADMIN_DEFAULT_EMAIL=user@domain.local' -e 'PGADMIN_DEFAULT_PASSWORD=postgresmaster'-d dpage/pgadmin4
In the above-given command, my-pgadmin is the name of the Docker PostgreSQL PGAdmin Container. PGADMIN_DEFAULT_EMAIL and PGADMIN_DEFAULT_PASSWORD are the username and passwords for the Docker PostgreSQL container, respectively.
- Following this, open your browser and search for the web address http://localhost:8081/. It will redirect you to the welcome page of the PGAdmin 4 Web Instance.
Image Source
- On the welcome page, it will ask you to enter the username and password of PGAdmin 4.
- Enter the credentials you defined while running the Docker Container of PGAdmin.
Image Source
- Upon logging in with PGAdmin 4, you will see the main page where you have to set up a connection between the GUI tool and the Postgres server.
- Click on the “Add New Server” icon on the main page. It will open a new dialogue box asking you to fill in two mandatory fields, such as “General” and “Connection.”
Image Source
- In the General tab, provide a name to uniquely identify the connection between PostgreSQL and PGAdmin 4. Then, fill in the Server group by selecting the Server options from the drop-down menu.
- Now, switch to the Connection tab under the same dialogue box and fill in the required fields.
Image Source
- Before filling in the connection details, you have to execute the following command to get the required information about connection settings.
docker inspect postgresql -f “{{json .NetworkSettings.Networks }}”
The above-given command will display your connection details in JSON format.
- In the connection tab, you can fill in the Hostname/address details according to the docker inspect command’s output.
- Fill the port value as 5432 that runs the Docker PostgreSQL Container and provide the name of the database as Postgres. Then, fill in the username and password fields with the credentials you created while running the PGAdmin container.
- After providing all the required details, click on the “Save” button.
Image Source
Now, your PGAdmin is connected to the Docker Postgres instance. You can see the newly created instance in the left side panel which confirms that the connection is successfully established between PGAdmin and Postgres.
In the PGAdmin dashboard, you can fully manage the PostgreSQL Instance that runs on the Docker Container and completely manage Docker PostgreSQL Environment. You can also query the PostgreSQL database by writing commands using the “Query Tool” from the PGAdmin dashboard.
Using the above-mentioned steps, you have successfully installed and set up a Docker Postgres Instance on Docker.
Conclusion
In this article, you learned about Docker PostgreSQL Container, and how to install, set up, and run the Docker Postgres Instance on your Docker. Since this blog mainly focused on managing Postgres instances using the web-based tool or interface called PGAdmin, you have learned the GUI way of interacting with Postgres instances on Docker. However, you can also use CLI (Command Line Interface tools) to connect with the PSQL server for executing queries on databases present in PostgreSQL.
If you would like to export data from a source of your choice like PostgreSQL into your desired database/destination like a data warehouse, then Hevo Data is the right choice for you!
Visit our Website to Explore Hevo
Hevo Data provides its users with a simpler platform for integrating data from 150+ Data sources for Data Migration and Analysis. It is a No-code Data Pipeline that can help you combine data from multiple sources. You can use it to transfer data from multiple data sources such as PostgreSQL into your Data Warehouses like Google BigQuery, Snowflake, Amazon Redshift, or Firebolt. It provides you with a consistent and reliable solution to manage data in real-time, ensuring that you always have an analysis-ready format in your desired destination.
Want to take Hevo for a spin? Sign Up for a 14-day free trial and experience the feature-rich Hevo suite firsthand. You can also have a look at the unbeatable Hevo Pricing that will help you choose the right plan for your business needs.
Share your experience of learning how to install and set up a Docker PostgreSQL environment! Let us know in the comments section below!
Ishwarya has experience working with B2B SaaS companies in the data industry and her passion for data science drives her to product informative content to aid individuals in comprehending the intricacies of data integration and analysis.