Skip to content

Lightweight Docker image for JDK 11 micro-services

License

Notifications You must be signed in to change notification settings

maslick/minimalka

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

=minimalka=

lightweight Docker image for JDK11 micro-services

image size Docker layers Docker pulls License: MIT

Features

Usage

Given your application jar is named my-cool-app.jar, create a Dockerfile with the following contents:

FROM maslick/minimalka:jdk11
WORKDIR /app
EXPOSE 8080
COPY my-cool-app.jar ./app.jar
CMD java $JAVA_OPTIONS -jar app.jar
docker build -t my-cool-app .
docker run -d my-cool-app:latest

Customize and build your own image

git clone https://github.com/maslick/minimalka.git && cd minimalka
vim Dockerfile
docker build -t my-minimalka:jdk11 .
FROM my-minimalka:jdk11
WORKDIR /app
EXPOSE 8080
COPY my-cool-app.jar ./app.jar
CMD java $JAVA_OPTIONS -jar app.jar
docker build -t my-cool-app .
docker run -d my-cool-app:latest

Demo

Install Corretto 11 JDK and use jenv to switch to it in your shell:

$ jenv add /Library/Java/JavaVirtualMachines/amazon-corretto-11.jdk/Contents/Home
$ jenv shell corretto64-11.0.13
$ java -version
openjdk version "11.0.13" 2021-10-19 LTS
OpenJDK Runtime Environment Corretto-11.0.13.8.1 (build 11.0.13+8-LTS)
OpenJDK 64-Bit Server VM Corretto-11.0.13.8.1 (build 11.0.13+8-LTS, mixed mode)
git clone https://github.com/maslick/minimalka.git
cd minimalka/demo
./gradlew dockerBuild
docker run -d -p 8080:8081 -e JAVA_OPTIONS=-Dserver.port=8081 minimalka-boot
open http://localhost:8080/helloworld

S2i binary build

This s2i image supports binary builds only. Meaning that the build stage doesn't build your jars, instead you provide already built artifacts. Minimalka s2i image will just check and copy your binaries into the resulting lightweight image.

s2i build . maslick/minimalka-s2i mycoolapp:latest

More or less it works in the same way as the Docker multistage builds. The resulting image is production ready and does not have the root privilage escalation flaw.

Integration with Openshift

In a typical use-case you would have a Jenkins pipeline with several stages: checkout, build, test, Build Docker image, Deploy to dev. During the Build Docker image stage you inject the already built jar (build stage) into the build config and start the build.

oc new-build --name minimalka-runtime --docker-image maslick/minimalka-s2i --binary=true
oc start-build minimalka-runtime --from-file my-cool-app.jar
oc new-app minimalka-runtime --name my-cool-app
oc expose svc my-cool-app

About

Lightweight Docker image for JDK 11 micro-services

Resources

License

Stars

Watchers

Forks

Packages

No packages published