Saltar al contenido principal
Versión: Next

Docker Deployment

Deploy Dimebia using Docker and Docker Compose for production-ready environments.

Prerequisites

  • Docker 24.0+
  • Docker Compose 2.20+
  • At least 2GB RAM and 10GB disk space

Quick Start

# Clone the repository
git clone https://github.com/alaikis/dimebia.git
cd dimebia

# Start all services
docker-compose up -d

# Check service status
docker-compose ps

Services

The Docker Compose setup includes:

ServicePortDescription
dimebia8080Main API server
mysql3306MySQL database
phpmyadmin8081Database management UI

Environment Variables

Create a .env file in the project root:

# Database
DB_URL=jdbc:mysql://mysql:3306/dimebia
DB_USERNAME=dimebia
DB_PASSWORD=your_secure_password

# JWT
APP_JWT_SECRET=your-secret-key-at-least-32-characters-long

# Deployment
DEPLOYMENT_MODE=private
JPA_DDL_AUTO=none

# Server
SERVER_PORT=8080

Docker Compose Configuration

version: '3.8'

services:
dimebia:
image: dimebia:latest
build:
context: .
dockerfile: docker/Dockerfile
ports:
- "8080:8080"
environment:
- DB_URL=jdbc:mysql://mysql:3306/dimebia
- DB_USERNAME=dimebia
- DB_PASSWORD=${DB_PASSWORD}
- APP_JWT_SECRET=${APP_JWT_SECRET}
- DEPLOYMENT_MODE=private
depends_on:
mysql:
condition: service_healthy
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
interval: 30s
timeout: 10s
retries: 3

mysql:
image: mysql:8.0
environment:
- MYSQL_ROOT_PASSWORD=${DB_ROOT_PASSWORD}
- MYSQL_DATABASE=dimebia
- MYSQL_USER=dimebia
- MYSQL_PASSWORD=${DB_PASSWORD}
volumes:
- mysql_data:/var/lib/mysql
- ./docker/mysql/conf.d:/etc/mysql/conf.d
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
interval: 10s
timeout: 5s
retries: 5

phpmyadmin:
image: phpmyadmin/phpmyadmin
ports:
- "8081:80"
environment:
- PMA_HOST=mysql
- MYSQL_ROOT_PASSWORD=${DB_ROOT_PASSWORD}

volumes:
mysql_data:

Building the Image

# Build the production image
docker build -f docker/Dockerfile -t dimebia:latest .

# Verify the image
docker images dimebia:latest

Production Configuration

Resource Limits

services:
dimebia:
deploy:
resources:
limits:
cpus: '2'
memory: 2G
reservations:
cpus: '1'
memory: 1G

Logging

services:
dimebia:
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"

Health Checks

services:
dimebia:
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s

Database Migrations

Flyway migrations run automatically on startup. To run manually:

docker exec -it dimebia ./gradlew :boot:flywayMigrate

Backup and Restore

Backup

docker exec mysql mysqldump -u dimebia -p dimebia > backup.sql

Restore

docker exec -i mysql mysql -u dimebia -p dimebia < backup.sql

Scaling

For horizontal scaling:

docker-compose up -d --scale dimebia=3

Use a load balancer (nginx, traefik) in front of the API instances.

Monitoring

Enable metrics endpoint:

curl http://localhost:8080/api/admin/monitor/metrics

Troubleshooting

Container Won't Start

# Check logs
docker-compose logs dimebia

# Common issues:
# - Database not ready: increase depends_on condition
# - Port already in use: change host port mapping
# - Insufficient memory: increase Docker memory limit

Database Connection Issues

# Verify MySQL is running
docker-compose exec mysql mysqladmin -u dimebia -p ping

# Check network connectivity
docker-compose exec dimebia ping mysql