A Dockerfile helps package your Spring Boot app into a container. This makes it easy to run your app anywhere without setup hassles.
Dockerfile for Spring Boot in Spring Boot
FROM openjdk:17-jdk-slim ARG JAR_FILE=target/*.jar COPY ${JAR_FILE} app.jar ENTRYPOINT ["java", "-jar", "/app.jar"]
FROM sets the base image with Java installed.
COPY moves your built app jar into the container.
ENTRYPOINT runs your app when the container starts.
FROM openjdk:17-jdk-slim COPY target/myapp.jar app.jar ENTRYPOINT ["java", "-jar", "/app.jar"]
FROM openjdk:17-jdk-slim ARG JAR_FILE=target/*.jar COPY ${JAR_FILE} app.jar ENTRYPOINT ["java", "-jar", "/app.jar"]
EXPOSE to tell Docker the app listens on port 8080.FROM openjdk:17-jdk-slim COPY target/myapp.jar app.jar EXPOSE 8080 ENTRYPOINT ["java", "-jar", "/app.jar"]
This Dockerfile creates a container image for your Spring Boot app. It uses Java 17, copies your built jar, exposes port 8080, and runs the app.
FROM openjdk:17-jdk-slim ARG JAR_FILE=target/*.jar COPY ${JAR_FILE} app.jar EXPOSE 8080 ENTRYPOINT ["java", "-jar", "/app.jar"]
Make sure your Spring Boot app is built (e.g., with ./mvnw package) before building the Docker image.
The EXPOSE instruction does not publish the port but documents it; use -p flag when running the container to map ports.
Use docker build -t myapp . to build and docker run -p 8080:8080 myapp to run your container.
A Dockerfile packages your Spring Boot app with Java into a container.
Use FROM, COPY, EXPOSE, and ENTRYPOINT to define the container.
Build your app first, then build and run the Docker image to run your app anywhere.