Spring Boot Docker Deployment Guide
To deploy a Spring Boot project to a Docker container, you can follow the steps below:
- Create a Dockerfile to define the configuration and environment of a Docker container. The Dockerfile can specify the base image, working directory, and copying project files among other things. A basic Dockerfile might look like this:
FROM openjdk:11
WORKDIR /app
COPY target/my-spring-boot-app.jar /app
CMD ["java", "-jar", "my-spring-boot-app.jar"]
- Execute the packaging command in the root directory of the Spring Boot project to package the project into an executable jar file.
mvn clean package
- Build a Docker image using a Dockerfile file.
docker build -t my-spring-boot-app .
- Run the Docker container to start the built image.
docker run -p 8080:8080 my-spring-boot-app
This way, the Spring Boot project can be deployed and run in a Docker container. You can access the project by visiting http://localhost:8080.