How to Deploy a Spring Boot Application with Docker
A reliable Spring Boot Docker deployment usually needs more than a Dockerfile. You also need environment variables, log volume mapping, restart policy, service dependencies and a repeatable startup script.
Minimal Dockerfile
FROM eclipse-temurin:17-jre
WORKDIR /app
COPY demo-api.jar app.jar
ENV SPRING_PROFILES_ACTIVE=prod
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]Docker Compose Checklist
- Use an explicit container name and restart policy.
- Map host log directories into `/app/logs`.
- Keep secrets in `.env`, not in committed Compose files.
- Use service names such as `mysql` and `redis` inside Docker networks.
Common Mistakes
The most frequent issues are wrong JAR names, missing production profiles, exposing database ports publicly, and using `localhost` from inside containers when the app should connect to another Compose service.