Setting Up PostgreSQL and pgAdmin with Docker on Linux Mousavi, October 30, 2023October 30, 2023 Docker is a powerful tool for containerization, making it easier to manage and deploy applications. In this article, I will walk you through the process of setting up a PostgreSQL database and the pgAdmin web interface using Docker on a Alma Linux system. We’ll be using the popular database management system, PostgreSQL, and the web-based administration tool, pgAdmin, to make managing your databases more convenient. Prerequisites: Before we begin, make sure you have the following prerequisites in place: A Linux-based system (I’ll use Alma Linux as an example). Docker installed on your system. If not, you can follow the official Docker installation guide for your specific distribution. Now, let’s get started: Step 1: Create a Docker Network First, we’ll create a Docker network that allows the PostgreSQL container and pgAdmin container to communicate with each other. Open your terminal and run the following command: docker network create pg_network Step 2: Run PostgreSQL in Docker Next, we will run a PostgreSQL container. You can specify the PostgreSQL version and credentials according to your needs. Replace your_password with your desired password: docker run --name pgadmin -e PGADMIN_DEFAULT_EMAIL=your_email -e PGADMIN_DEFAULT_PASSWORD=your_pgadmin_password -d --net pg_network -p 8080:80 dpage/pgadmin4 This command will download the PostgreSQL image and create a container named “postgres-db” with the specified password. You can choose to add other environment variables if needed. Step 3: Run pgAdmin in Docker Now, we’ll set up a pgAdmin container to manage our PostgreSQL database. Replace your_pgadmin_password with your desired password: docker run --name pgadmin -e PGADMIN_DEFAULT_EMAIL=your_email -e PGADMIN_DEFAULT_PASSWORD=your_pgadmin_password -d --net pg_network -p 8080:80 dpage/pgadmin4 This command will download the pgAdmin image and create a container named “pgadmin.” It also maps port 8080 of your host system to port 80 of the pgAdmin container for web access. Step 4: Access pgAdmin Web Interface Open a web browser and navigate to http://localhost:8080. You will be greeted with the pgAdmin login page. Use the credentials you set in the previous step to log in. Step 5: Add PostgreSQL Server in pgAdmin In the pgAdmin web interface, click on “Add New Server.” Provide a name for the server and switch to the “Connection” tab. Fill in the following details: Click “Save” to add the PostgreSQL server to pgAdmin. Conclusion: With PostgreSQL and pgAdmin running in Docker containers, you have a convenient way to manage your database system and access it from a web interface. This setup is flexible and can be easily customized to suit your specific requirements. Docker makes it straightforward to set up, run, and manage these services without interfering with your local system configuration. Host name/address: postgres-db Linux Server Configuration almalinuxdockerlinuxpgadminpostgresql