Sign inSign up

jesusperales/spring-boot

By jesusperales

•Updated almost 7 years ago

Docker base image for Spring Boot applications with Amazon Corretto and Java 11.

Image
1

2.2K

jesusperales/spring-boot repository overview

⁠Spring Boot Docker Base Image

⁠What is this?

⁠It's a fork of the original spring boot base⁠ image with Amazon Corretto⁠ and Java 11

Docker base image, following Docker image best-practices⁠, for Spring Boot applications.

Some features:

  • The Spring Boot application runs as a non-root user inside the container
  • Injection of JVM- and application arguments at runtime
  • Wrapper script that will forward Unix signals (example: SIGINT) to the Spring Boot application
  • Runs on RedHat OpenShift out of the box

⁠How do I use it?

Using this base image to create an image for your Spring Boot application is easy:

  1. Create a new Dockerfile and use this image as the FROM image
  2. Make sure the Spring Boot application jar (must be named app.jar) file is in the same directory as the Dockerfile you've created above
  3. Build your Dockerfile

Here's an example on how you would use it (Replace /path/to/spring/boot/application.jar to the actual path of your Spring Boot application jar file):

mkdir bootapp-docker && cd bootapp-docker
echo "FROM jesusperales/spring-boot" > Dockerfile
cp /path/to/spring/boot/application.jar ./app.jar
docker build -t bootapp-docker .
docker run -p 8007:8007 bootapp-docker

Then open up your browser to http://localhost:8007/⁠ and you should see your Spring Boot application's index page.

⁠Injecting JVM- and application arguments

To inject JVM- and application arguments during runtime, simply override the BOOTAPP_JAVA_OPTS (for JVM) and BOOTAPP_OPTS (for application) environment variables. Example:

docker run -p 8007:8007 \
  -e BOOTAPP_JAVA_OPTS="-Xms512m -Xmx1024m" \
  -e BOOTAPP_OPTS="--spring.profiles.active=test --spring.main.banner-mode=off" \
  bootapp-docker

⁠Example Project

https://github.com/EtienneK/spring-boot-admin⁠

⁠Multi-stage builds

If you use docker mulit-stage builds you need create an app.jar file :

echo 'workaround for use multi-stage builds' >> app.jar 

And this is a Dockerfile example:

FROM maven:alpine AS build
ADD pom.xml /usr/src/app/
ADD src /usr/src/app/src
RUN mvn -f /usr/src/app/pom.xml clean package -Dmaven.test.skip=true

FROM jesusperales/spring-boot
COPY --from=build /usr/src/app/target/*.jar /
EXPOSE 8007

Tag summary

Content type

Image

Digest

Size

317.6 MB

Last updated

almost 7 years ago

docker pull jesusperales/spring-boot