Spring Boot E-commerce Application using Thymeleaf as UI
10K+
A full-stack e-commerce web application built with Spring Boot, Thymeleaf, and HTMX. This Docker image contains a complete monolithic application that combines backend services and frontend presentation for a seamless e-commerce experience.
Create a docker-compose.yml file:
services:
mysql:
image: gussttaav/g-commerce-mysql:latest
environment:
MYSQL_ROOT_PASSWORD: rootpassword
MYSQL_USER: dbuser
MYSQL_PASSWORD: dbpassword
ports:
- "3306:3306"
volumes:
- mysql_data:/var/lib/mysql
networks:
- g-commerce-network
restart: unless-stopped
webapp:
image: gussttaav/g-commerce-thymeleaf:latest
depends_on:
- mysql
environment:
SPRING_DATASOURCE_USERNAME: dbuser
SPRING_DATASOURCE_PASSWORD: dbpassword
# Logging configuration
LOG_PATH: /app/logs
LOG_MAX_FILE_SIZE: 50MB
LOG_MAX_HISTORY: 15
LOG_TOTAL_SIZE_CAP: 500MB
volumes:
# Optional: Mount logs directory for external access
- ./logs:/app/logs
ports:
- "8080:8080"
networks:
- g-commerce-network
restart: unless-stopped
networks:
g-commerce-network:
driver: bridge
volumes:
mysql_data:
Then run:
docker-compose up -d
The application will be available at http://localhost:8080
The application includes a comprehensive logging system designed for production environments and containerized deployments.
g-commerce.log - Main application logs with all eventsg-commerce-error.log - Error-level logs only for quick troubleshootingg-commerce-security.log - Security events and authentication audit trailg-commerce-performance.log - Performance monitoring and metrics| Variable | Description | Default | Required |
|---|---|---|---|
MYSQL_ROOT_PASSWORD | MySQL root password | - | Yes |
MYSQL_USER | Database user | - | Yes |
MYSQL_PASSWORD | Database password | - | Yes |
MYSQL_HOST | Database host name and port | localhost:3306 | No |
| Variable | Description | Default | Required |
|---|---|---|---|
LOG_PATH | Directory for log files | logs | No |
LOG_ARCHIVE | Directory for archived logs | logs/archive | No |
LOG_MAX_FILE_SIZE | Maximum size per log file | 100MB | No |
LOG_MAX_HISTORY | Days to keep archived logs | 30 | No |
LOG_TOTAL_SIZE_CAP | Total size limit for all logs | 1GB | No |
# Run with default logging configuration
docker run -p 8080:8080 \
-e MYSQL_USER=dbuser \
-e MYSQL_PASSWORD=dbpass \
gussttaav/g-commerce-thymeleaf:latest
# Mount logs directory to host filesystem
docker run -p 8080:8080 \
-v /host/path/logs:/app/logs \
-e LOG_PATH=/app/logs \
-e MYSQL_USER=dbuser \
-e MYSQL_PASSWORD=dbpass \
gussttaav/g-commerce-thymeleaf:latest
# Configure log rotation and retention
docker run -p 8080:8080 \
-v ./logs:/app/logs \
-e LOG_PATH=/app/logs \
-e LOG_MAX_FILE_SIZE=50MB \
-e LOG_MAX_HISTORY=15 \
-e LOG_TOTAL_SIZE_CAP=500MB \
gussttaav/g-commerce-thymeleaf:latest
services:
mysql:
image: gussttaav/g-commerce-mysql:latest
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
volumes:
- mysql_data:/var/lib/mysql
networks:
- g-commerce-network
restart: unless-stopped
webapp:
image: gussttaav/g-commerce-thymeleaf:latest
depends_on:
- mysql
environment:
SPRING_DATASOURCE_USERNAME: ${MYSQL_USER}
SPRING_DATASOURCE_PASSWORD: ${MYSQL_PASSWORD}
SPRING_PROFILES_ACTIVE: prod
# Production logging configuration
LOG_PATH: /app/logs
LOG_MAX_FILE_SIZE: 100MB
LOG_MAX_HISTORY: 30
LOG_TOTAL_SIZE_CAP: 1GB
ports:
- "8080:8080"
volumes:
# External log storage for monitoring and backup
- /var/log/g-commerce:/app/logs
networks:
- g-commerce-network
restart: unless-stopped
# Health check
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/actuator/health"]
interval: 30s
timeout: 10s
retries: 3
networks:
g-commerce-network:
driver: bridge
volumes:
mysql_data:
View logs in real-time:
# Main application logs
docker exec -it <container_name> tail -f /app/logs/g-commerce.log
# Error logs only
docker exec -it <container_name> tail -f /app/logs/g-commerce-error.log
# Security events
docker exec -it <container_name> tail -f /app/logs/g-commerce-security.log
With mounted volumes:
# View from host filesystem
tail -f ./logs/g-commerce.log
tail -f ./logs/g-commerce-error.log
The logs include structured information for easy parsing:
Example log entry:
2024-06-03 10:15:30.123 INFO [http-nio-8080-exec-1] c.g.commerce.controllers.ProductController - User admin accessed product catalog
eclipse-temurin:21-jdk/workspace/appjava -jar app.jar/workspace/app/logs (default)/actuator/healthgussttaav/g-commerce-mysql:latest
This project is licensed under the MIT License.
Content type
Image
Digest
sha256:604eff8bf…
Size
145.9 MB
Last updated
over 1 year ago
docker pull gussttaav/g-commerce-thymeleaf