This document describes the Docker setup for the Mem4j application.
# Copy environment variables
cp env.example .env
# Edit .env with your actual values
# Start core services (recommended for development)
docker-compose up -d
# Or start with all optional services
docker-compose --profile full up -d# Start with development overrides
docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d
# Includes debugging port (5005) and Adminer for database management# Start with production optimizations
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d
# Includes optimized JVM settings and resource limitsThe Docker Compose setup supports different profiles for optional services:
- Default: Core services (mem4j, postgres, qdrant, neo4j)
- elasticsearch: Adds Elasticsearch
- weaviate: Adds Weaviate vector database
- full: All services including optional ones
- monitoring: Prometheus + Grafana (production only)
# Start with Elasticsearch
docker-compose --profile elasticsearch up -d
# Start with Weaviate
docker-compose --profile weaviate up -d
# Start everything
docker-compose --profile full up -d
# Production with monitoring
docker-compose -f docker-compose.yml -f docker-compose.prod.yml --profile monitoring up -d| Service | Port | Description |
|---|---|---|
| mem4j | 8080 | Main application |
| postgres | 5432 | Primary database |
| qdrant | 6333, 6334 | Vector database |
| neo4j | 7474, 7687 | Graph database |
| Service | Port | Profile | Description |
|---|---|---|---|
| elasticsearch | 9200 | elasticsearch | Search engine |
| weaviate | 8081 | weaviate | Alternative vector DB |
| adminer | 8082 | dev only | Database admin tool |
| prometheus | 9090 | monitoring | Metrics collection |
| grafana | 3000 | monitoring | Metrics visualization |
Create a .env file from env.example:
cp env.example .envKey variables:
DASHSCOPE_API_KEY: Required for LLM functionalityOPENAI_API_KEY: Optional, for OpenAI servicesPOSTGRES_PASSWORD: Database passwordNEO4J_PASSWORD: Neo4j passwordJAVA_OPTS: JVM options for the application
Create docker-compose.override.yml for local customization:
cp docker-compose.override.yml.example docker-compose.override.ymlAll services include health checks:
- mem4j:
/api/v1/memory/search?query=test&userId=health(fallback endpoint) - postgres:
pg_isready - neo4j:
cypher-shell - qdrant:
/health - elasticsearch:
/_cluster/health - weaviate:
/v1/.well-known/ready
Note: The application doesn't currently include Spring Boot Actuator, so health checks use the memory API endpoint.
Services are configured with resource limits appropriate for their role:
- mem4j: 1.5G memory, 1 CPU
- postgres: 512M memory, 0.5 CPU
- neo4j: 1.5G memory, 1 CPU
- qdrant: 1G memory, 0.5 CPU
- mem4j: 2.5G memory, 2 CPU
- postgres: 1G memory, 1 CPU
- neo4j: 2.5G memory, 1.5 CPU
- qdrant: 2G memory, 1 CPU
- Service fails to start: Check logs with
docker-compose logs <service> - Memory issues: Increase Docker memory allocation
- Port conflicts: Modify port mappings in override file
- Permission issues: Ensure proper file ownership
# View logs
docker-compose logs -f mem4j
# Restart specific service
docker-compose restart mem4j
# Check service health
docker-compose ps
# Clean up
docker-compose down -v # Warning: removes data volumes- All services run as non-root users where possible
- Resource limits are enforced
- No sensitive data in images
- Health checks ensure service availability
- Optional services use profiles to reduce attack surface
In production, enable monitoring stack:
docker-compose -f docker-compose.yml -f docker-compose.prod.yml --profile monitoring up -dAccess:
- Grafana: http://localhost:3000 (admin/admin)
- Prometheus: http://localhost:9090
Important volumes to backup:
postgres_data: Application dataneo4j_data: Graph databaseqdrant_data: Vector embeddings