This repository provides a Dockerfile that runs the latest built JAR from target/.
Build the application artifact first (using the included Maven wrapper):
./mvnw -DskipTests packageThen build the Docker image. The Dockerfile accepts an optional build-arg JAR_FILE so you can specify the exact jar if you have multiple in target/.
Default (auto-uses target/*.jar):
# from project root
docker build -t product-management-api:latest .If you want to point to a specific jar (example target/Mvc-0.0.1-SNAPSHOT.jar):
docker build --build-arg JAR_FILE=target/Mvc-0.0.1-SNAPSHOT.jar -t product-management-api:latest .Run the container (example):
docker run -e SPRING_DATASOURCE_URL=jdbc:mysql://host.docker.internal:3306/mobile \
-e SPRING_DATASOURCE_USERNAME=ganesh \
-e SPRING_DATASOURCE_PASSWORD=Ganesh@123! \
-e SPRING_MAIL_HOST=smtp.gmail.com \
-e SPRING_MAIL_PORT=587 \
-e SPRING_MAIL_USERNAME=you@example.com \
-e SPRING_MAIL_PASSWORD=yourpassword \
-p 8081:8081 \
product-management-api:latestNotes
- By default the Dockerfile exposes port 8081 (same as your Spring Boot server.port).
- Avoid baking secrets inside the image. Use environment variables at
docker runtime or a secret manager. - If your MySQL server runs on the host where you build the image, Docker Desktop provides
host.docker.internalto reach the host from the container on many platforms; adjust the JDBC URL accordingly for your environment.