This repository provides a simple way to spin up a PostgreSQL database along with the PgAdmin tool using Docker Compose. With just a few commands, you can have a fully functional PostgreSQL environment running in seconds.
Make sure you have the following installed on your machine:
Follow these steps to quickly launch PostgreSQL and PgAdmin:
-
Clone this repository:
git clone https://github.com/EriksonMurrugarra/postgres-pgadmin-docker-setup.git cd postgres-pgadmin-docker-setup -
Launch the containers:
docker-compose up -d
This will start both PostgreSQL and PgAdmin in detached mode.
-
Access PgAdmin:
Once the containers are running, you can access PgAdmin via your web browser by visiting:
http://localhost:8888 -
Login to PgAdmin:
Use the following credentials to login:
- Email:
pgadmin@example.com - Password:
admin
- Email:
-
Add a new PostgreSQL server in PgAdmin:
- Host:
postgres - Port:
5432 - Username:
admin - Password:
admin
- Host:
You are now ready to manage your PostgreSQL database!
Here’s the content of the docker-compose.yml file used in this setup:
version: '3.9'
services:
postgres:
image: postgres:14-alpine
ports:
- 5432:5432
volumes:
- myDatabaseVol:/var/lib/postgresql/data
environment:
- POSTGRES_PASSWORD=admin
- POSTGRES_USER=admin
- POSTGRES_DB=mydb
pgadmin:
image: dpage/pgadmin4
restart: always
ports:
- "8888:80"
environment:
PGADMIN_DEFAULT_EMAIL: pgadmin@example.com
PGADMIN_DEFAULT_PASSWORD: admin
volumes:
- pgAdminVol:/var/lib/pgadmin
depends_on:
- postgres
volumes:
myDatabaseVol:
pgAdminVol:-
Postgres Service: Runs the PostgreSQL database, accessible via port
5432on the host machine. The database is namedmydb, and the default user isadminwith the passwordadmin. -
PgAdmin Service: Runs PgAdmin, accessible via port
8888on your browser. The default login credentials for PgAdmin are provided as environment variables.
To stop and remove the containers, run:
docker-compose downThis will stop the containers and remove the network. The data stored in the database will persist across restarts due to the volume configuration.
-
To view container logs:
docker-compose logs -f
-
To stop the containers without removing them:
docker-compose stop
-
To remove containers and volumes:
docker-compose down -v
-
If you encounter any issues with container startup, check the logs by running:
docker-compose logs
-
Make sure the required ports (
5432for Postgres and8888for PgAdmin) are available and not being used by other applications.