Documentation (6 files, 1500+ lines): Tutorials (3): - 01-deploy-rds-database.md: Deploy PostgreSQL in private network - 02-data-persistence.md: Data persistence with named volumes - 03-security-compliance.md: INF-01/02/03/04 compliance How-to Guides (1): - connect-to-postgresql.md: Connection methods Reference (1): - postgresql-commands.md: PostgreSQL command reference Explanation (1): - database-rds-parallels.md: Docker↔RDS parallels with architecture diagrams Key concepts: - PostgreSQL container → RDS Instance - Private network → VPC Private Subnet - Named volume → EBS volume - Resource limits → DB instance class Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
60 lines
1.1 KiB
Markdown
60 lines
1.1 KiB
Markdown
# How-to: Connettersi a PostgreSQL in Docker
|
|
|
|
## Come connettersi al database
|
|
|
|
### Da container nella stessa rete
|
|
|
|
```bash
|
|
docker exec lab05-app psql -h db -U lab05_user -d lab05_db
|
|
```
|
|
|
|
### Dall'host con port forwarding (non recommended)
|
|
|
|
Se devi connetterti dall'host, aggiungi temporaneamente:
|
|
|
|
```yaml
|
|
# docker-compose.yml
|
|
ports:
|
|
- "127.0.0.1:5432:5432"
|
|
```
|
|
|
|
Poi:
|
|
|
|
```bash
|
|
psql -h 127.0.0.1 -U lab05_user -d lab05_db
|
|
```
|
|
|
|
### Con pgAdmin o altri tool
|
|
|
|
1. Configura connection string:
|
|
```
|
|
host=127.0.0.1 port=5432 user=lab05_user password=lab05_password dbname=lab05_db
|
|
```
|
|
|
|
2. Oppure usa PostgreSQL URI:
|
|
```
|
|
postgresql://lab05_user:lab05_password@127.0.0.1:5432/lab05_db
|
|
```
|
|
|
|
## Risoluzione problemi
|
|
|
|
### Connection refused
|
|
|
|
Il database è in rete privata. Devi connetterti da container nella stessa rete:
|
|
|
|
```bash
|
|
# Prima entra in un container
|
|
docker exec -it lab05-app sh
|
|
|
|
# Poi connettiti
|
|
psql -h db -U lab05_user -d lab05_db
|
|
```
|
|
|
|
### Password authentication failed
|
|
|
|
Verifica le credenziali in docker-compose.yml:
|
|
|
|
```bash
|
|
grep POSTGRES_PASSWORD docker-compose.yml
|
|
```
|