This Spring Boot 4.0 application demonstrates:
- H2 database integration
- Flyway data migration
- Docker containerization with multi-stage builds
- Spring Boot Actuator for health monitoring
- Security best practices for containerization
- Java 17 or later
- Docker Desktop (latest version)
- Maven 3.6+
# Clone the repository
git clone https://github.com/Arun4D/spring-boot-docker.git
cd spring-boot-docker
# Build and run locally
mvn clean installPowerShell:
$env:DOCKER_BUILDKIT=1Bash:
export DOCKER_BUILDKIT=1# Build the Docker image
docker build -t spring-boot-docker:latest .
# Run the container
docker run -d \
--name spring-boot-app \
-p 8080:8080 \
-e "SPRING_PROFILES_ACTIVE=default" \
spring-boot-docker:latest
# Check container health
docker ps
docker logs spring-boot-app- Multi-stage build for smaller final image
- Maven cache optimization
- Eclipse Temurin JDK 17 (recommended for Spring Boot 4.0)
- Security hardening with non-root user
- Built-in health checks
- Container-optimized JVM settings
Access the persons API:
http://localhost:8080/api/persons
http://localhost:8080/actuator/health
Access the H2 database console when running:
- Locally:
http://localhost:8080/h2-console/
- Docker:
http://localhost:8080/h2-console/
Database Connection Details:
JDBC URL : jdbc:h2:mem:PersonDB
User Name : sa
Password : [leave empty]
| Variable | Description | Default |
|---|---|---|
| SPRING_PROFILES_ACTIVE | Active Spring profile | default |
| JAVA_OPTS | JVM options | -XX:+UseContainerSupport -XX:MaxRAMPercentage=75.0 |
- Application runs as non-root user (UID 1001)
- Container includes security hardening
- Uses OpenJDK (Eclipse Temurin) for better security updates
- Health checks enabled by default
- View container logs:
docker logs spring-boot-app- Check container health:
docker inspect spring-boot-app | jq '.[0].State.Health'- Access container shell:
docker exec -it spring-boot-app shOpen the browser and hit the following url to invoke the service.