Prerequisites
Before you begin, ensure you have the following installed on your system:- Docker (version 20.10 or higher)
- Docker Compose (version 2.0 or higher)
The application uses multi-stage Docker builds to optimize image sizes and improve security.
Quick start
Configure environment variables
Create a Open the
.env file from the example template:.env file and configure the required variables. See the environment variables page for detailed information.Start the application
Launch all services using Docker Compose:The
--build flag ensures Docker builds the latest images for the frontend and backend services.Verify deployment
Once all containers are running, access the application:
- Frontend: http://localhost:3000
- Backend API: http://localhost:8080
- Health endpoint: http://localhost:8080/actuator/health
Container architecture
The application consists of four main services:Database service
PostgreSQL 15 database running on Alpine Linux for data persistence.- Image:
postgres:15-alpine - Container name:
library-db - Port mapping:
5432:5432 - Volume:
postgres_data:/var/lib/postgresql/data - Restart policy:
always
Backend service
Spring Boot application handling all business logic and API endpoints.- Build context:
./apps/spring-boot-app - Container name:
library-backend - Port mapping:
${BACKEND_PORT:-8080}:8080(defaults to 8080) - Restart policy:
always - Dependencies: Database and cache services must be healthy
Cache service
Redis cache for improving application performance.- Image:
redis:7-alpine - Container name:
library-cache - Internal port:
6379 - Restart policy:
always
Frontend service
Next.js application providing the user interface.- Build context:
./apps/nextjs-app - Container name:
library-frontend - Port mapping:
3000:3000 - Restart policy:
always - Dependencies: Backend service must be healthy
Health checks
All services include health checks to ensure proper startup sequencing and monitoring.The backend and frontend services have a
start_period configuration, giving them additional time to initialize before health checks begin.Docker build process
Backend Dockerfile
The Spring Boot application uses a multi-stage build:Build stage
Uses
maven:3.9.7-eclipse-temurin-21 to compile the application:- Downloads Maven dependencies
- Compiles source code with Java 21
- Packages the application as a JAR file
Frontend Dockerfile
The Next.js application also uses a multi-stage build:Build stage
Uses
node:24-alpine to build the application:- Installs npm dependencies
- Runs the Next.js build process
- Creates an optimized standalone output
Common commands
Infrastructure-only deployment
If you want to run only the database and cache services (for local development), use the infrastructure compose file:- PostgreSQL database on port 5432
- Redis cache on port 6379
Volume management
The application uses a named volume for PostgreSQL data persistence:Troubleshooting
Container fails to start
Check the container logs:Database connection issues
Verify the database is healthy:Port conflicts
If ports 3000, 5432, or 8080 are already in use, you can modify the port mappings incompose.yaml or change the BACKEND_PORT in your .env file.
Rebuilding after code changes
After making code changes, rebuild the affected service:The application uses Spring DevTools and Next.js hot reload in development mode. However, these features only work when running the applications directly, not in Docker containers.