2025-11-27 15:37:16 +00:00
# OBP-API Docker Development Setup
2025-07-15 14:40:32 +00:00
2025-11-27 15:37:16 +00:00
This Docker Compose setup provides a complete development environment for OBP-API with Redis caching support.
2025-07-15 14:40:32 +00:00
2025-11-27 15:37:16 +00:00
## Services
2025-07-15 14:40:32 +00:00
2025-11-27 15:37:16 +00:00
### 🏦 **obp-api-app**
- Main OBP-API application
- Built with Maven 3 + OpenJDK 17
- Runs on Jetty 9.4
- Port: `8080`
### 🔴 **obp-api-redis**
- Redis cache server
- Version: Redis 7 Alpine
- Internal port: `6379`
- External port: `6380` (configurable)
- Persistent storage with AOF
## Quick Start
2025-07-15 14:40:32 +00:00
2025-11-27 15:37:16 +00:00
1. **Prerequisites**
- Docker and Docker Compose installed
- Local PostgreSQL database running
- Props file configured at `obp-api/src/main/resources/props/default.props`
2025-07-15 14:40:32 +00:00
2025-11-27 15:37:16 +00:00
2. **Start services**
```bash
cd development/docker
docker-compose up --build
```
2025-07-15 14:40:32 +00:00
2025-11-27 15:37:16 +00:00
3. **Access application**
- OBP-API: http://localhost:8080
- Redis: `localhost:6380`
2025-07-15 14:40:32 +00:00
2025-11-27 15:37:16 +00:00
## Configuration
### Database Connection
Your `default.props` should use `host.docker.internal` to connect to your local database:
2025-07-15 14:40:32 +00:00
```properties
2025-11-27 15:37:16 +00:00
db.driver=org.postgresql.Driver
db.url=jdbc:postgresql://host.docker.internal:5432/obp_mapped?user=obp& password=yourpassword
```
2025-07-15 14:40:32 +00:00
2025-11-27 15:37:16 +00:00
**Note**: The Docker setup automatically overrides the database URL via environment variable, so you can also configure it without modifying props files.
2025-07-15 14:40:32 +00:00
2025-11-27 15:37:16 +00:00
### Redis Configuration
Redis is configured automatically using OBP-API's environment variable override system:
2025-07-15 14:40:32 +00:00
2025-11-27 15:37:16 +00:00
```yaml
# Automatically set by docker-compose.yml:
OBP_CACHE_REDIS_URL=redis # Connect to redis service
OBP_CACHE_REDIS_PORT=6379 # Internal Docker port
OBP_DB_URL=jdbc:postgresql://host.docker.internal:5432/obp_mapped?user=obp& password=f
```
2025-07-15 14:40:32 +00:00
2025-11-27 15:37:16 +00:00
### Custom Redis Port
To customize configuration, edit `.env` :
2025-07-15 14:40:32 +00:00
```bash
2025-11-27 15:37:16 +00:00
# .env file
OBP_CACHE_REDIS_PORT=6381
OBP_DB_URL=jdbc:postgresql://host.docker.internal:5432/mydb?user=myuser& password=mypass
2025-07-15 14:40:32 +00:00
```
2025-11-27 15:37:16 +00:00
Or set environment variables:
2025-07-15 14:40:32 +00:00
2025-11-27 15:37:16 +00:00
```bash
export OBP_CACHE_REDIS_PORT=6381
export OBP_DB_URL="jdbc:postgresql://host.docker.internal:5432/mydb?user=myuser& password=mypass"
docker-compose up --build
```
2025-07-15 14:40:32 +00:00
2025-11-27 15:37:16 +00:00
## Container Names
2025-07-15 14:40:32 +00:00
2025-11-27 15:37:16 +00:00
All containers use consistent `obp-api-*` naming:
2025-07-15 14:40:32 +00:00
2025-11-27 15:37:16 +00:00
- `obp-api-app` - Main application
- `obp-api-redis` - Redis cache server
- `obp-api-network` - Docker network
- `obp-api-redis-data` - Redis data volume
2025-07-15 14:40:32 +00:00
2025-11-27 15:37:16 +00:00
## Development Features
2025-07-15 14:40:32 +00:00
2025-11-27 15:37:16 +00:00
### Props File Override
2025-07-15 14:40:32 +00:00
2025-11-27 15:37:16 +00:00
The setup mounts your local props directory:
```yaml
volumes:
- ../../obp-api/src/main/resources/props:/app/props
```
2025-07-15 14:40:32 +00:00
2025-11-27 15:37:16 +00:00
Environment variables take precedence over props files using OBP's built-in system:
- `cache.redis.url` → `OBP_CACHE_REDIS_URL`
- `cache.redis.port` → `OBP_CACHE_REDIS_PORT`
- `db.url` → `OBP_DB_URL`
2025-07-15 14:40:32 +00:00
2025-11-27 15:37:16 +00:00
### Live Development
For code changes without rebuilds:
```yaml
# docker-compose.override.yml provides:
volumes:
- ../../obp-api:/app/obp-api
- ../../obp-commons:/app/obp-commons
2025-07-15 14:40:32 +00:00
```
2025-11-27 15:37:16 +00:00
## Useful Commands
2025-07-15 14:40:32 +00:00
2025-11-27 15:37:16 +00:00
### Service Management
2025-07-15 14:40:32 +00:00
```bash
2025-11-27 15:37:16 +00:00
# Start services
docker-compose up -d
# View logs
docker-compose logs obp-api-app
docker-compose logs obp-api-redis
# Stop services
2025-07-15 14:40:32 +00:00
docker-compose down
2025-11-27 15:37:16 +00:00
# Rebuild and restart
docker-compose up --build
2025-07-15 14:40:32 +00:00
```
2025-11-27 15:37:16 +00:00
### Redis Operations
```bash
# Connect to Redis CLI
docker exec -it obp-api-redis redis-cli
2025-07-15 14:40:32 +00:00
2025-11-27 15:37:16 +00:00
# Check Redis keys
docker exec obp-api-redis redis-cli KEYS "*"
2025-07-15 14:40:32 +00:00
2025-11-27 15:37:16 +00:00
# Monitor Redis commands
docker exec obp-api-redis redis-cli MONITOR
```
2025-07-15 14:40:32 +00:00
2025-11-27 15:37:16 +00:00
### Container Inspection
2025-07-15 14:40:32 +00:00
```bash
2025-11-27 15:37:16 +00:00
# List containers
docker-compose ps
# Execute commands in containers
docker exec -it obp-api-app bash
docker exec -it obp-api-redis sh
2025-07-15 14:40:32 +00:00
```
2025-11-27 15:37:16 +00:00
## Troubleshooting
2025-07-15 14:40:32 +00:00
2025-11-27 15:37:16 +00:00
### Redis Connection Issues
- Check if `OBP_CACHE_REDIS_URL=redis` is set correctly
- Verify Redis container is running: `docker-compose ps`
- Test Redis connection: `docker exec obp-api-redis redis-cli ping`
2025-07-15 14:40:32 +00:00
2025-11-27 15:37:16 +00:00
### Database Connection Issues
- Ensure local PostgreSQL is running
- Verify `host.docker.internal` resolves: `docker exec obp-api-app ping host.docker.internal`
- Check props file is mounted: `docker exec obp-api-app ls /app/props/`
2025-07-15 14:40:32 +00:00
2025-11-27 15:37:16 +00:00
### Props Loading Issues
- Check external props are detected: `docker-compose logs obp-api-app | grep "external props"`
- Verify environment variables: `docker exec obp-api-app env | grep OBP_`
2025-07-15 14:40:32 +00:00
2025-11-27 15:37:16 +00:00
## Environment Variables
2025-07-15 14:40:32 +00:00
2025-11-27 15:37:16 +00:00
The setup uses OBP-API's built-in environment override system:
| Props File Property | Environment Variable | Default | Description |
|---------------------|---------------------|---------|-------------|
| `cache.redis.url` | `OBP_CACHE_REDIS_URL` | `redis` | Redis hostname |
| `cache.redis.port` | `OBP_CACHE_REDIS_PORT` | `6379` | Redis port |
| `cache.redis.password` | `OBP_CACHE_REDIS_PASSWORD` | - | Redis password |
| `db.url` | `OBP_DB_URL` | `jdbc:postgresql://host.docker.internal:5432/obp_mapped?user=obp&password=f` | Database connection URL |
## Network Architecture
```
Host Machine
├── PostgreSQL :5432
└── Docker Network (obp-api-network)
├── obp-api-app :8080 → :8080
└── obp-api-redis :6379 → :6380
2025-07-15 14:40:32 +00:00
```
2025-11-27 15:37:16 +00:00
- OBP-API connects to Redis via internal Docker network (`redis:6379`)
- OBP-API connects to PostgreSQL via `host.docker.internal:5432`
- Redis is accessible from host via `localhost:6380`
## Notes
- Container builds use multi-stage Dockerfile for optimized images
- Redis data persists in `obp-api-redis-data` volume
- Props files are mounted from host for easy development
- Environment variables override props file values automatically
- All containers restart automatically unless stopped manually
---
2025-07-15 14:40:32 +00:00
2025-11-27 15:37:16 +00:00
🚀 **Ready to develop!** Run `docker-compose up --build` and start coding.