Overview
Trippins uses a multi-stage Docker build process to create an optimized production image that combines the Angular frontend and Spring Boot backend into a single deployable container.The Docker setup uses a three-stage build process: Angular compilation, Maven build with frontend integration, and final runtime image.
Architecture
The deployment consists of two main services:MySQL Database
MySQL 8.0.33 container for persistent data storage
Application Server
Spring Boot application with embedded Angular frontend
Dockerfile
The Dockerfile uses a multi-stage build to optimize the final image size:Build Stages
Stage 1: Angular Build
- Base image:
node:19.0.1 - Installs npm dependencies including chart.js
- Builds Angular application for production
- Sets base href to
/new/for routing
Stage 2: Maven Build
- Base image:
maven:3.8.4-openjdk-17 - Downloads Maven dependencies offline
- Copies compiled Angular files to Spring Boot static resources
- Packages the application as a JAR file
Docker Compose Configuration
Thedocker-compose.yml file orchestrates both the database and application services:
Service Configuration
Database Service (db)
Database Service (db)
Image: MySQL 8.0.33Environment Variables:
MYSQL_DATABASE: TrippinsMYSQL_ROOT_PASSWORD: password
3307:3306 (host:container)Volume: db_data mounted to /var/lib/mysql for data persistenceNetwork: Connected to trippins-networkApplication Service (web)
Application Service (web)
Build Context: Parent directory with Dockerfile in
docker/ subdirectoryImage: jantoniio3/trippins:latestPort Mapping: 443:8443 (HTTPS)Dependencies: Waits for db service to startEnvironment Variables:SPRING_DATASOURCE_URL: Connection to MySQL containerSPRING_DATASOURCE_USERNAME: rootSPRING_DATASOURCE_PASSWORD: passwordJWT_SECRET: passwordSERVER_SSL_ENABLED: trueSERVER_PORT: 8443
on-failureNetwork: Connected to trippins-networkDeployment Commands
Build and Run Locally
Production Deployment Script
Theimage.sh script automates building, tagging, and pushing the image to Docker Hub:
Port Mappings
| Service | Host Port | Container Port | Protocol | Description |
|---|---|---|---|---|
| Database | 3307 | 3306 | TCP | MySQL database access |
| Application | 443 | 8443 | HTTPS | Application HTTPS endpoint |
The application runs on port 8443 internally but is exposed on port 443 for standard HTTPS access.
Networking
All services communicate through a custom bridge network calledtrippins-network. This allows:
- Service discovery by container name
- Isolated network environment
- Secure inter-service communication
Volume Management
Database Persistence
Thedb_data volume ensures that database data persists across container restarts:
Environment Variables
The following environment variables can be overridden in the docker-compose file:JDBC URL for MySQL database connectionDefault:
jdbc:mysql://db:3306/TrippinsDatabase usernameDefault:
rootDatabase passwordDefault:
passwordSecret key for JWT token generationDefault:
passwordEnable/disable SSLDefault:
trueInternal application portDefault:
8443Troubleshooting
Container won't start
Container won't start
Check logs for errors:Verify database is ready:
Cannot connect to database
Cannot connect to database
Ensure the database container is running:Check network connectivity:
Port already in use
Port already in use
Change the host port mapping in
docker-compose.yml:Build fails during Maven stage
Build fails during Maven stage
Clear Docker build cache:
Next Steps
Configuration
Configure application settings and environment variables
Database Setup
Learn about the database schema and initialization
