Prerequisites
Before you begin, you will need to have the following prerequisites:- A system running Windows, macOS, or Linux
- Docker installed on your system
- Basic knowledge of using the command line
Installing Docker
If you don’t have Docker installed on your system, you can download and install it from the official Docker website. Follow the instructions provided on the website to install Docker on your system. Once the docker is installed, you can verify the installation by running the following command in your terminal:Create Storage Directory
Now that you have Docker installed, create a new directory for your PostgreSQL data. This directory will be used to store the data files for your PostgreSQL instance. I usually keep this directory in my project folder so that it is easy to manage.Docker Compose File
Now, create a new file namedcompose.yml in the same directory. This file will contain the configuration for your PostgreSQL container.
Insert the following content into the compose.yml file:
db and adminer. The db service is responsible for running the PostgreSQL instance, while the adminer service is responsible for running the Adminer web interface. It is a lightweight database management tool that allows you to interact with your databases through a web interface.
The db service uses the postgres image from the Docker Hub registry. We specify the volume mapping to store the data files in the ./data/db directory. The ports section maps the container port 5432 to the host port 5432, allowing you to access the PostgreSQL instance from your local machine.
We also set the environment variables POSTGRES_DB, POSTGRES_USER, and POSTGRES_PASSWORD to configure the database name, username, and password, respectively.
The adminer service uses the adminer image from the Docker Hub registry. We map the container port 8080 to the host port 8080 to access the Adminer web interface.
Environment Variables
To configure the database name, username, and password, you can create a.env file in the same directory as the compose.yml file. Add the following content to the .env file:
DB_NAME, DB_USER, and DB_PASSWORD with your desired database name, username, and password, respectively.
Start the PostgreSQL Container
Now that you have created thecompose.yml file, you can start the PostgreSQL container by running the following command in the terminal:
db and adminer containers listed in the output.
You can now access the Adminer web interface by opening a web browser and navigating to http://localhost:8080. In the login page, enter the database name, username, and password that you specified in the compose.yml file. You should now be able to interact with your PostgreSQL database through the Adminer web interface.
Connect with PostgreSQL
If you want to connect with database url, you can use the following url:Summary
In this tutorial, we have learned how to set up PostgreSQL using Docker on your system. We have also learned how to connect with the database using the Adminer web interface.Next: Setting Up PostgreSQL On VPS
Continue your journey by learning how to set up PostgreSQL on a VPS.

