This directory contains a Docker Compose setup for PostgreSQL, a powerful open-source relational database, and Adminer, a lightweight web-based database management tool.
- PostgreSQL Docker Setup with Adminer
- Table of Contents
⚠️ Make sure Docker or the Docker daemon is running on your device before proceeding.
-
Navigate to the
docker-database/postgresqldirectory:cd docker-database/postgresql -
Start the PostgreSQL and Adminer containers:
docker compose up -d
-
Verify that the containers are running:
docker ps
This command should list the
postgresandadminercontainers as running.
You can connect to the PostgreSQL database using any PostgreSQL client, such as pgAdmin, TablePlus, or psql.
Note: The default database created is
my_database. You can change this in thedocker-compose.ymlfile if needed, or create a new database after the setup to fit your requirements.
Use the following host and port to connect to PostgreSQL from any PostgreSQL client:
Host: <HOST_IP> # Replace with your machine's IP, e.g., 192.168.x.x or 127.0.0.1 or localhost
Port: 5432
Database: my_database
User: admin
Password: password
Use the following host and port:
Host: postgres
Port: 5432
Database: my_database
User: admin
Password: password
Since both containers are on the same Docker network, postgres is automatically resolvable as the hostname.
Use the host and port of the host machine running Docker:
Host: <HOST_IP> # Replace with the local network IP of the host machine, e.g., 192.168.x.x
Port: 5432
Database: my_database
User: admin
Password: password
Use the following:
Host: <HOST_IP> # The IP address of the host machine on the local network
Port: 5432
Database: my_database
User: admin
Password: password
Ensure that the host's firewall allows incoming connections on port 5432.
Adminer is a web-based database management tool for PostgreSQL. Once the containers are running, you can access Adminer from your browser.
http://localhost:8080
or
http://127.0.0.1:8080
or
<HOST_IP>:8080
- Open your browser and go to
http://localhost:8080orhttp://127.0.0.1:8080or<HOST_IP>:8080. - In the Adminer interface, enter the following details:
- System: PostgreSQL
- Server:
postgres(or<HOST_IP>if connecting from another device) - Username:
admin - Password:
password - Database:
my_database
- Click "Login" to access and manage your PostgreSQL database.
From a terminal on the host machine:
psql -h <HOST_IP> -p 5432 -U admin -d my_databaseExample:
psql -h 127.0.0.1 -p 5432 -U admin -d my_databaseThis provides direct access to PostgreSQL for running SQL commands and managing the database.
To stop the containers:
docker compose downTo restart the containers:
docker compose up -dHere's the conclusion section for the PostgreSQL README.md file:
With this setup, you have a fully functional PostgreSQL database and a user-friendly interface through Adminer for managing and interacting with your data. This environment is ideal for local development, testing, and learning purposes. Feel free to customize the configuration as needed to suit your project requirements.
Happy coding! 🚀