Skip to content

Docker Quick Start Guide

🚀 Get Started in 3 Steps

1. Start the Application

docker-compose up -d

2. Verify It's Running

curl http://localhost:8080/actuator/health

3. Access the Application

  • API: http://localhost:8080
  • Swagger UI: http://localhost:8080/swagger-ui.html

📋 Common Commands

Start & Stop

# Start all services
docker-compose up -d

# Stop all services
docker-compose down

# Restart services
docker-compose restart

# Stop and remove volumes (clean slate)
docker-compose down -v

View Logs

# All services
docker-compose logs -f

# Application only
docker-compose logs -f app

# Last 100 lines
docker-compose logs --tail=100 app

Check Status

# Service status
docker-compose ps

# Resource usage
docker stats

# Health check
curl http://localhost:8080/actuator/health

Rebuild

# Rebuild and restart
docker-compose up -d --build

# Force rebuild (no cache)
docker-compose build --no-cache

🔧 Configuration

Change Port

Edit docker-compose.yml:

services:
  app:
    ports:
      - "9090:8080"  # Change 9090 to your desired port

Increase Memory

Edit docker-compose.yml:

services:
  app:
    environment:
      - JAVA_OPTS=-Xmx1g -Xms512m

Enable Debug Logging

docker-compose up -d -e LOGGING_LEVEL_COM_ANR=DEBUG

🐛 Troubleshooting

Application Won't Start

# Check logs
docker-compose logs app

# Check if MongoDB is running
docker-compose ps mongodb

Port Already in Use

# Find process using port 8080
lsof -i :8080

# Or change port in docker-compose.yml

MongoDB Connection Issues

# Test MongoDB
docker-compose exec mongodb mongosh --eval "db.runCommand({ ping: 1 })"

# Restart MongoDB
docker-compose restart mongodb

Clean Everything

# Remove all containers, networks, and volumes
docker-compose down -v

# Remove images
docker rmi sprboot-api-cktbrkr:latest

# Start fresh
docker-compose up -d --build

📊 Monitoring

Health Checks

# Application health
curl http://localhost:8080/actuator/health

# MongoDB health
docker-compose exec mongodb mongosh --eval "db.adminCommand('ping')"

Metrics

# Application metrics
curl http://localhost:8080/actuator/metrics

# Container stats
docker stats

🔐 Security

Change Default Password

Edit docker-compose.yml:

services:
  app:
    environment:
      - SPRING_SECURITY_USER_PASSWORD=your-secure-password

Don't Expose MongoDB

Edit docker-compose.yml:

services:
  mongodb:
    ports: []  # Remove this line to not expose MongoDB


📚 More Information


Need Help? Check the full DOCKER.md guide for detailed instructions.