Managing and installing relational databases through a web-based management tool is a ubiquitous requirement for many software projects. pgAdmin is an excellent tool in this regard, especially if you don’t like to use the command-line interface to manage your database. It is a web-based front-end for PostgreSQL. With the help of container-based technologies like Docker, we can set our environment up within minutes. We don’t have to install PostgreSQL or pgAdmin because Docker takes care of that for us. Additionally, Docker allows you to run this project on macOS, Windows, and Linux distributions.
This guide explains how to establish a pgAdmin Docker connection seamlessly. It also gives a brief introduction to PostgreSQL, Docker, and PgAdmin before diving into the pgAdmin Docker Connection steps.
Table of Contents
- What is PostgreSQL?
- What is PgAdmin?
- What is Docker?
- Understanding the PgAdmin Docker Setup Process
This step by step tutorial is written based on the following requirements:
- Operating System: Mac OS
- Docker Community: v.20.10.7 for Mac
What is PostgreSQL?
This powerful open-source object-relational database management system is also known as PostgreSQL. The SQL language used in Postgres is extended with a host of features that allow it to store and scale the most complex data workloads safely. Over the last three decades, it has undergone continuous development. As a result, many companies and organizations have chosen it for its robust architecture and assurance of high reliability, data integrity, and correctness.
PostgreSQL runs on various major platforms like Windows, Linux, macOS, and UNIX to name a few. Concurrency is managed by PostgreSQL through Multi-Version Concurrency Control (MVCC). MVCC provides each transaction a “Database Snapshot” that allows changes to be made without impacting other transactions. This ensures the maintenance of ACID principles while doing away with the need to read locks.
Key Features of PostgreSQL
- Customizable: PostgreSQL can be customized by developing plugins to make the Database Management System fit your requirements. PostgreSQL also allows you to incorporate custom functions that are made with other programming languages like Java, C, C++, etc.
- Long History: PostgreSQL has been around for more than 30 years, having been initially released in 1988.
- Frequent Updates: The most recent PostgreSQL update was Version 13.1 on 12 November 2020.
- MVCC Features: PostgreSQL happens to be the first Database Management System to implement Multi-Version Concurrency Control (MVCC) features.
- A Supportive Community: A dedicated community is always at your disposal. Private, third-party support services are available as well. The community updates the PostgreSQL platform via the PostgreSQL Global Development Group.
- Open-Source: This is an Object-Relational Database Management System(ORDBMS). This allows PostgreSQL to provide Object-Oriented and Relational Database functionality. PostgreSQL is a free and Open-Source ORDBMS.
- Users: PostgreSQL users include Apple, Cisco, Etsy, Facebook, Instagram, Red Hat, Skype, Spotify, Yahoo to name a few.
What is PgAdmin?
PgAdmin is an open-source GUI tool that provides easy access to Postgres databases through a web-based GUI. The user interface allows database administrators to manage databases, tables, columns, relations, indexes, users, permissions, and any other database administration operations without worrying about running SQL statements. It is written in Python and jQuery, using Bootstrap with the Flask framework.
What is Docker?
Docker simplifies creating, deploying, and running applications using containers. Using this approach, developers can package up a complete application in a container and ship it out as a single package. Docker’s extensive end-to-end platform consists of CLIs, UIs, and APIs along with robust security measures engineered to work together across the entire application delivery lifecycle.
Docker Containers are a standardized unit of software that lets developers isolate their app from the environment, therefore, solving the localized operation problem. Docker has grown to become the go-to standard for sharing and building containerized apps for virtually millions of developers- from the Cloud to Desktops.
Key Features of Docker
Here are a few salient features of Docker that allow it to stand out of the crowd:
- Ease of Packaging: Docker allows you to package applications as portable container images to function in any conducive environment consistently from AWS ECS to on-premise Kubernetes, Google GKE, Azure ACI, and so much more.
- Large Pantheon of Images to Choose From: You can use Docker Trusted Content that includes pictures from the Docker Verified Publishers from the Docker Hub Repository along with Docker Official images for your specific business use case.
- Seamless Integrations: With Docker, you can seamlessly integrate with your favorite tools across your development pipeline. Docker works well with all development tools that you leverage including CircleCI, VS Code, and GitHub among others.
- Personalized Developer Access: Docker lets you personalize your developer access to images via roles-based access control. Thus, Docker allows you to extract insights into activity history with the help of Docker Hub Audit Logs.
- Ease of Deployment: Docker lets you deploy your applications in different containers independently and in a vast array of languages as well. Thus, by leveraging Docker you can minimize the risk of conflict between libraries, languages, and frameworks.
Simplify your PostgreSQL ETL with Hevo’s No-code Data Pipeline
A fully managed No-code Data Pipeline platform like Hevo helps you integrate data from 100+ data sources (including 40+ Free Data Sources) like PostgreSQL to a destination of your choice like PostgreSQL in real-time in an effortless manner. Hevo with its minimal learning curve can be set up in just a few minutes allowing the users to load data without having to compromise performance. Its strong integration with umpteenth sources provides users with the flexibility to bring in data of different kinds, in a smooth fashion without having to code a single line.GET STARTED WITH HEVO FOR FREE
Check Out Some of the Cool Features of Hevo:
- Completely Automated: The Hevo platform can be set up in just a few minutes and requires minimal maintenance.
- Real-Time Data Transfer: Hevo provides real-time data migration, so you can have analysis-ready data always.
- Transformations: Hevo provides preload transformations through Python code. It also allows you to run transformation code for each event in the Data Pipelines you set up. You need to edit the event object’s properties received in the transform method as a parameter to carry out the transformation. Hevo also offers drag and drop transformations like Date and Control Functions, JSON, and Event Manipulation to name a few. These can be configured and tested before putting them to use.
- Connectors: Hevo supports 100+ Integrations to SaaS platforms, files, databases, analytics, and BI tools. It supports various destinations including Amazon Redshift, Firebolt, Snowflake Data Warehouses; Databricks, Amazon S3 Data Lakes, MySQL, SQL Server, TokuDB, DynamoDB, PostgreSQL databases to name a few.
- 100% Complete & Accurate Data Transfer: Hevo’s robust infrastructure ensures reliable data transfer with zero data loss.
- Scalable Infrastructure: Hevo has in-built integrations for 100+ sources, that can help you scale your data infrastructure as required.
- 24/7 Live Support: The Hevo team is available round the clock to extend exceptional support to you through chat, email, and support calls.
- 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.
- Live Monitoring: Hevo allows you to monitor the data flow so you can check where your data is at a particular point in time.
Simplify your Data Analysis with Hevo today!SIGN UP HERE FOR A 14-DAY FREE TRIAL!
Understanding the PgAdmin Docker Setup Process
Here are the steps involved in setting up a PgAdmin Docker connection in a seamless fashion:
- PgAdmin Docker Setup: Installation of Docker
- PgAdmin Docker Setup: Docker Images and Docker Compose
- PgAdmin Docker Setup: Creating The Docker Compose File
- PgAdmin Docker Setup: Verification of Docker Connection
- PgAdmin Docker Setup: Set up the PostgreSQL Connection
PgAdmin Docker Setup: Installation of Docker
This PgAdmin Docker Setup step must be done to follow the tutorial, but this is not covered here because Docker provides an excellent explanation. Please refer to https://www.docker.com and follow the steps.
PgAdmin Docker Setup: Docker Images and Docker Compose
You must understand where and why we create a file or change it for now during the PgAdmin Docker Setup process:
- Docker Images: As you probably know, Docker images are the basis of Container creation. They are the templates that we will use to “generate” our Docker environment. Docker Hub has a variety of Docker images.
- Docker Compose: Compose allows you to define and run multi-container Docker applications. First, you configure Compose’s services by using a YAML file. Afterward, you can start all the services from your configuration with a single command.
PgAdmin Docker Setup: Creating The Docker Compose File
- Step 1: The first step in creating the Docker Compose file for PgAdmin Docker Setup is to create a file that will “orchestrate” the installation and setup of PostgreSQL and PGAdmin. Create one file in any folder of your choosing and name it: docker-compose.yml. This file will contain the following code:
version: '3.8' services: db: container_name: postgres_container image: postgres restart: always environment: POSTGRES_DB: postgres_db POSTGRES_USER: admin POSTGRES_PASSWORD: secret PGDATA: /var/lib/postgresql/data ports: - "5432:5432" volumes: - db-data:/var/lib/postgresql/data pgadmin: container_name: pgadmin4_container image: dpage/pgadmin4:5.5 restart: always environment: PGADMIN_DEFAULT_EMAIL: email@example.com PGADMIN_DEFAULT_PASSWORD: secret PGADMIN_LISTEN_PORT: 80 ports: - "8080:80" volumes: - pgadmin-data:/var/lib/pgadmin volumes: db-data: pgadmin-data:
- Step 2: You can start using your database from this moment, but let’s take a moment to look at the parameters we see here.
- Version: ‘3.8’: This is the version of the ‘tool’ that will be used, which is docker-compose, and to interpret it, we need to tell which version of docker-compose will be used, which is 3-8.
- Services: We add all the ‘services’ that we will be running here. In this example, we have two services: db and PgAdmin, and within each service, we have different configurations.
- container_name, image, and restart: We need to specify a name for our container in the order. This will be important later when we tell our PgAdmin where/how to connect.
Image: In other words, this is the “image” that we want to use, and it’s the “VM” that we want to use when we build. There are more images available on the Docker hub.
- Restart: As a result of stopping our Docker container, you can specify this option to restart it automatically unless you completely shut down your Docker.
- Environment: Since our container is a closed system, we must declare the environment variables available to each container using the keyword “environment”.
- Ports: Our goal here is to redirect outside access from our docker image to the image that we have set up. With PgAdmin, we request, for example, that port number 8080 be redirected/forwarded to port 80 of our container/docker image when we access it from our machine.
- Volumes: While this step is not mandatory, it helps us organize our files. When we create our container, we’ll need a path to persist the data for each image; if we don’t specify, Docker will automatically create one, but we like to label it in advance if we decide to delete it.
PgAdmin Docker Setup: Verification of Docker Connection
- Step 1: Now that we are ready to start building the PgAdmin Docker connection, let’s make sure we have our Docker up and running. If you want to make sure that Docker is running, type: docker info.
- Step 2: You can now go into the folder you created for your docker-compose file and type this command: docker-compose up.
- Step 3: The first thing that will happen upon running this command for the first time is downloading the images you specified in your docker-compose file. You should see this if everything is working correctly. It will show that you are ready to access it.
- Step 4: Using your browser, you can now type either of the following: http://localhost:8080 or http://127.0.0.1:8080.
- Step 5: Based on the docker-compose file configuration, you will see the screen as follows:
Email: firstname.lastname@example.org Password: secret
- Step 6: When you see this screen, that means everything is fine, and your PGAdmin is up and running. Furthermore, you should check the terminal you used to launch the docker images to see if the requests are processed for the PgAdmin Docker setup.
PgAdmin Docker Setup: Set up the PostgreSQL Connection
- Step 1: Next, we need to add PGAdmin access to our database to manage and use it for the PgAdmin Docker setup. Select “Add New Server”, and you should see a screen like this one.
- Step 2: It’s not essential which name you enter in the field name, as this is only for the organization within the tool. The critical part is the next.
- Step 3: Click on the “Connection” tab, and in the field “Hostname/address”, type in the name that appears on the docker-compose file for this Postgres container:
- Step 4: Also, you will use the username and password that you specified in your docker-compose:
Username: admin Password: secret
- Step 5: It is vital to use the Docker container name so that we do not need to know the container’s IP address to restart without any problems. To visualize this, here is the basic process we use to create these containers:
- Step 6: It is possible to communicate between the components inside the “Docker” using either the hostname or IP address. Since the hostname is permanently fixed, we will use it here.
- Step 7: Here are the two steps you can take to determine what your container’s internal IP address is: 1 – Get the identifier of your Postgres container using the command: docker ps. 2 – Print the IP address of this docker image using its identifier: Docker inspect b5c2c4484e15 | grep IPAddress. This should give you the following:
- Step 8: Okay, back to creating the container; after entering the container name, user and password just hit save.
- Step 9: The connection to the database has been established. We can now create a database table, manage users and quickly adjust our PostgreSQL database.
Managing databases via a command-line interface can be stressful. Developers can use a tool with a graphical interface to overcome this issue. The pgAdmin solves this problem.
Additionally, Docker simplifies the entire process. Hopefully, this guide will help you get started with PostgreSQL, pgAdmin, and Docker. Happy coding!
Extracting complex data from a diverse set of data sources can be a challenging task and this is where Hevo saves the day! Hevo offers a faster way to move data from Databases or SaaS applications like PostgreSQL into your Data Warehouse or a destination like PostgreSQL to be visualized in a BI tool. Hevo is fully automated and hence does not require you to code.Visit our Website to Explore Hevo
Hevo Data will automate your data transfer process, hence allowing you to focus on other aspects of your business like Analytics, Customer Management, etc. This platform allows you to transfer data from 100+ multiple sources such as PostgreSQL to Cloud-based Data Warehouses like Snowflake, Google BigQuery, Amazon Redshift, etc. It will provide you with a hassle-free experience and make your work life much easier.
Want to take Hevo for a spin? Sign Up for a 14-day free trial and experience the feature-rich Hevo suite first handYou can also have a look at our unbeatable pricing that will help you choose the right plan for your business needs!