How to use database with docker?

Guide to Setting Up PostgreSQL and Adminer with Docker in a Single File
Hello, I'm Cem Levent Avcı. This documentation details the step-by-step process of quickly bringing up a PostgreSQL database and the Adminer management interface using Docker Compose, all within a single configuration file.
What is Docker?
Docker is a platform that allows applications to be packaged with their dependencies and run in isolated environments (containers). Its purpose is to ensure the application can be consistently transported from one environment to another.
A container is a lightweight, standalone package that includes all the code, runtime, system tools, and libraries needed for an application to run.
This eliminates the "It works on my machine!" problem and minimizes incompatibilities between development and production environments.
What is PostgreSQL?
PostgreSQL is a powerful, open-source, and advanced Relational Database Management System (RDBMS). It is known for its high performance, scalability, data integrity, and ability to manage complex queries.
Due to its reliability and feature richness, it is widely used, from large-scale applications to small projects.
It uses the SQL language and adheres strictly to ACID (Atomicity, Consistency, Isolation, Durability) principles.
What is Adminer?
Adminer, much like phpMyAdmin, is a minimalist tool designed for managing databases through a web interface. It stands out for consisting of a single PHP file and supporting many different database types (MySQL, PostgreSQL, SQLite, Oracle, etc.).
How to Set It Up
Now, let's look at how to bring up these two core components (PostgreSQL and Adminer) with a single command.
1) Create the Folder Structure
First, create a folder for your project and name it, for example, postgresqlwithdocker.
2) Create the Configuration Files
docker-compose.yml file
version: '3.9'
services:
db:
image: postgres:15
container_name: postgres-db
restart: always
env_file:
- .env
ports:
- "${POSTGRES_PORT_HOST:-5432}:5432"
volumes:
- pgdata:/var/lib/postgresql/data
adminer:
image: adminer
restart: always
environment:
ADMINER_DEFAULT_SERVER: ${ADMINER_DEFAULT_SERVER:-db}
ports:
- "${POSTGRES_ADMIN_PORT:-8090}:8080"
volumes:
pgdata:.env file
POSTGRES_USER=
POSTGRES_PASSWORD=
POSTGRES_DB= # database name
POSTGRES_PORT_HOST=5432 # default port
POSTGRES_ADMIN_PORT=8090 # adminer port
ADMINER_DEFAULT_SERVER=db3) Start the Containers
docker compose up -d4) Check Container Status
docker psIf everything is running correctly, you should see two containers, postgres-db and adminer, in the Up status.
5) Access the Database via Adminer
http://localhost:8090/Use the following information to connect in the Adminer interface:
System:
PostgreSQLServer:
db(The value ofADMINER_DEFAULT_SERVERin the.envfile)Username: The value of
POSTGRES_USERfrom the.envfilePassword: The value of
POSTGRES_PASSWORDfrom the.envfileDatabase: The value of
POSTGRES_DBfrom the.envfile
Click the Login button to access your database and manage your tables.
You can also access the database using a feature-rich desktop database management tool, such as DBeaver.
Download and install DBeaver from the official link: https://dbeaver.io/download/.
Once the application opens, select the database type (PostgreSQL) from the Connect Your Database section and click Next.
On the following page, configure the connection settings:
jdbc:postgresql://localhost:5432/{your_db_name}?user={POSTGRES_USER}&password={POSTGRES_PASSWORD}Click the Finish button. You can view the database tables and other details through the established connection.
Thank you for reading! I hope this practical information on quickly setting up PostgreSQL and Adminer with Docker has been helpful. Don't forget to use Docker tips like this to speed up your development processes.
Feel free to reach out to me with any questions, feedback, or project collaborations. Exchanging ideas on technology, software, and automation is always very valuable to me.
Bana aşağıdaki kanallardan ulaşabilirsiniz:
Email: cemlevent54@gmail.com
LinkedIn: linkedin.com/in/leventavci54
GitHub: github.com/cemlevent54
Personal Website: https://cemleventavci.com.tr You can visit to see my portfolio and projects.

