Skip to content

Latest commit

 

History

History
43 lines (32 loc) · 1.51 KB

File metadata and controls

43 lines (32 loc) · 1.51 KB

Dockerfile for Product Management API

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 package

Then 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:latest

Notes

  • 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 run time or a secret manager.
  • If your MySQL server runs on the host where you build the image, Docker Desktop provides host.docker.internal to reach the host from the container on many platforms; adjust the JDBC URL accordingly for your environment.