PostgreSQL + pgAdmin
PostgreSQL database with pgAdmin web interface for easy database management and visualization.
Overview
PostgreSQL is a powerful, open-source object-relational database system with over 35 years of active development, known for its reliability, ACID compliance, and advanced features like JSON/JSONB support, full-text search, and extensible type system. Unlike simpler databases, PostgreSQL excels at complex queries, data integrity, and mixed relational-document workloads, making it the preferred choice for enterprise applications and data-intensive systems. pgAdmin4 complements PostgreSQL by providing a comprehensive web-based administration platform specifically designed for PostgreSQL management. This combination eliminates the complexity of command-line database administration while maintaining full access to PostgreSQL's advanced features through an intuitive graphical interface that includes visual query building, performance monitoring, and automated backup tools. This stack is ideal for development teams, database administrators, and organizations that need robust database capabilities with user-friendly management tools. The pairing is particularly valuable for development environments where multiple team members need database access, production systems requiring regular monitoring and maintenance, and educational settings where visual database exploration enhances learning.
Key Features
- ACID compliance with advanced transaction support and multi-version concurrency control
- JSON and JSONB data types for hybrid relational-document data models
- Web-based SQL editor with syntax highlighting and intelligent autocomplete
- Visual query builder for constructing complex queries without writing SQL
- Real-time database performance monitoring with query statistics and execution plans
- Built-in backup and restore functionality with scheduling capabilities
- Full-text search with ranking, highlighting, and multiple language support
- PostGIS compatibility for geospatial data operations and geographic queries
Common Use Cases
- 1Development teams building web applications requiring complex relational data with occasional document-style storage
- 2Small to medium businesses needing enterprise-grade database features with intuitive management tools
- 3Educational institutions teaching database concepts with hands-on PostgreSQL experience
- 4Startups migrating from SQLite or MySQL seeking better JSON support and query capabilities
- 5Data analysts requiring visual query building and result export functionality
- 6Organizations implementing microservices that need shared database infrastructure with centralized administration
- 7GIS applications leveraging PostGIS extensions for location-based services and mapping
Prerequisites
- Minimum 1.5GB RAM for both services (PostgreSQL: 1GB, pgAdmin: 512MB)
- Ports 5432 and 5050 available on the host system
- Basic understanding of SQL concepts and database relationships
- Familiarity with environment variables for database credentials configuration
- Docker Engine 20.10+ with Docker Compose V2 support
For development & testing. Review security settings, change default credentials, and test thoroughly before production use. See Terms
docker-compose.yml
docker-compose.yml
1services: 2 postgres: 3 image: postgres:16-alpine4 container_name: postgres5 restart: unless-stopped6 environment: 7 POSTGRES_USER: ${POSTGRES_USER}8 POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}9 POSTGRES_DB: ${POSTGRES_DB}10 volumes: 11 - postgres_data:/var/lib/postgresql/data12 ports: 13 - "5432:5432"14 networks: 15 - postgres-network1617 pgadmin: 18 image: dpage/pgadmin4:latest19 container_name: pgadmin20 restart: unless-stopped21 environment: 22 PGADMIN_DEFAULT_EMAIL: ${PGADMIN_EMAIL}23 PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_PASSWORD}24 volumes: 25 - pgadmin_data:/var/lib/pgadmin26 ports: 27 - "5050:80"28 depends_on: 29 - postgres30 networks: 31 - postgres-network3233volumes: 34 postgres_data: 35 pgadmin_data: 3637networks: 38 postgres-network: 39 driver: bridge.env Template
.env
1# PostgreSQL Configuration2POSTGRES_USER=admin3POSTGRES_PASSWORD=changeme4POSTGRES_DB=myapp56# pgAdmin Configuration7PGADMIN_EMAIL=admin@example.com8PGADMIN_PASSWORD=changemeUsage Notes
- 1Docs: https://www.postgresql.org/docs/ | pgAdmin: https://www.pgadmin.org/docs/
- 2Access pgAdmin at http://localhost:5050 with your PGADMIN_EMAIL/PASSWORD
- 3In pgAdmin, add server with hostname 'postgres', port 5432, and your POSTGRES_USER credentials
- 4Enable pg_stat_statements for query performance monitoring
- 5Backup: docker exec postgres pg_dumpall -U admin > backup.sql
- 6Data persisted in postgres_data volume - backup regularly
Individual Services(2 services)
Copy individual services to mix and match with your existing compose files.
postgres
postgres:
image: postgres:16-alpine
container_name: postgres
restart: unless-stopped
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
volumes:
- postgres_data:/var/lib/postgresql/data
ports:
- "5432:5432"
networks:
- postgres-network
pgadmin
pgadmin:
image: dpage/pgadmin4:latest
container_name: pgadmin
restart: unless-stopped
environment:
PGADMIN_DEFAULT_EMAIL: ${PGADMIN_EMAIL}
PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_PASSWORD}
volumes:
- pgadmin_data:/var/lib/pgadmin
ports:
- "5050:80"
depends_on:
- postgres
networks:
- postgres-network
Quick Start
terminal
1# 1. Create the compose file2cat > docker-compose.yml << 'EOF'3services:4 postgres:5 image: postgres:16-alpine6 container_name: postgres7 restart: unless-stopped8 environment:9 POSTGRES_USER: ${POSTGRES_USER}10 POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}11 POSTGRES_DB: ${POSTGRES_DB}12 volumes:13 - postgres_data:/var/lib/postgresql/data14 ports:15 - "5432:5432"16 networks:17 - postgres-network1819 pgadmin:20 image: dpage/pgadmin4:latest21 container_name: pgadmin22 restart: unless-stopped23 environment:24 PGADMIN_DEFAULT_EMAIL: ${PGADMIN_EMAIL}25 PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_PASSWORD}26 volumes:27 - pgadmin_data:/var/lib/pgadmin28 ports:29 - "5050:80"30 depends_on:31 - postgres32 networks:33 - postgres-network3435volumes:36 postgres_data:37 pgadmin_data:3839networks:40 postgres-network:41 driver: bridge42EOF4344# 2. Create the .env file45cat > .env << 'EOF'46# PostgreSQL Configuration47POSTGRES_USER=admin48POSTGRES_PASSWORD=changeme49POSTGRES_DB=myapp5051# pgAdmin Configuration52PGADMIN_EMAIL=admin@example.com53PGADMIN_PASSWORD=changeme54EOF5556# 3. Start the services57docker compose up -d5859# 4. View logs60docker compose logs -fOne-Liner
Run this command to download and set up the recipe in one step:
terminal
1curl -fsSL https://docker.recipes/api/recipes/postgres-pgadmin/run | bashTroubleshooting
- Connection refused on port 5432: Ensure PostgreSQL container is fully started before pgAdmin attempts connection, check docker logs postgres
- pgAdmin login fails with 'Invalid credentials': Verify PGADMIN_DEFAULT_EMAIL and PGADMIN_DEFAULT_PASSWORD environment variables are set correctly
- Cannot connect to server 'postgres' in pgAdmin: Use hostname 'postgres' (container name) not 'localhost' when adding server in pgAdmin interface
- PostgreSQL data lost after container restart: Confirm postgres_data volume is properly mounted and check volume permissions
- High memory usage warnings: Adjust PostgreSQL shared_buffers and work_mem settings via POSTGRES_INITDB_ARGS environment variable
- pgAdmin interface loads slowly: Increase pgAdmin container memory allocation or disable unnecessary pgAdmin features in configuration
Community Notes
Loading...
Loading notes...
Download Recipe Kit
Get all files in a ready-to-deploy package
Includes docker-compose.yml, .env template, README, and license
Ad Space
Shortcuts: C CopyF FavoriteD Download