Created
July 26, 2018 13:25
-
-
Save phillipuniverse/64bad55cdbecbe22cc16dfb1ed0f3903 to your computer and use it in GitHub Desktop.
Spring Boot exectuable jar Dockerfile with JAVA_OPTS, debugging and JRebel support
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Used as a base image that other Spring Boot-based | |
# docker containers can be based off of. Example dependent Dockerfile: | |
# | |
# FROM <this-image> | |
# ADD target/myjar.jar /app.jar | |
# | |
# Alternatively, you can modify this file to use a build arg: | |
# ... | |
# ... | |
# ARG JAR_FILE | |
# ADD ${JAR_FILE} app.jar | |
# | |
# and then build with: | |
# | |
# docker build --build-arg JAR_FILE=target/myjar.jar . | |
# | |
# This image can be built in 2 modes: | |
# 1. Normal - assumes an /app.jar is present as a fat Spring-Bootified jar file (executes with java -jar) | |
# 2. Jrebel - also downloads the Jrebel agent embedded in the image. An image with the JRebel agent downloaded | |
# can set a JREBEL environment variable (must be a non-empty string) to activate the Jrebel JVM parameters. | |
# This relies on JRebel remoting and a rebel-remote.xml built into the /app.jar | |
FROM openjdk:8u151-jdk-alpine | |
VOLUME /tmp | |
ADD run-app.sh run-app.sh | |
RUN chmod +x run-app.sh | |
ADD wait-for.sh wait-for.sh | |
RUN chmod +x wait-for.sh | |
# Only downloads jrebel if the argument is set | |
ARG JREBEL | |
ENV JREBEL=${JREBEL} | |
ADD download-jrebel.sh download-jrebel.sh | |
RUN chmod +x download-jrebel.sh && ./download-jrebel.sh | |
ENTRYPOINT ./run-app.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if [ -z ${JREBEL} ]; then | |
echo "Set the JREBEL argument to download and use JRebel remoting inside the container" | |
else | |
apk --no-cache add wget unzip | |
wget http://dl.zeroturnaround.com/jrebel-stable-nosetup.zip | |
unzip jrebel-stable-nosetup.zip | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if [ "$DEBUG_PORT" ]; then | |
export JAVA_OPTS="$JAVA_OPTS -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=$DEBUG_PORT" | |
fi | |
if [ "$JREBEL" ]; then | |
export JREBEL_ARGS="-agentpath:jrebel/lib/libjrebel64.so -Drebel.remoting_plugin=true" | |
export JAVA_OPTS="$JAVA_OPTS $JREBEL_ARGS" | |
fi | |
# Moved into a shell script because the above 'export' statements cannot be retrieved | |
# between multiple statements in a Dockerfile | |
echo "Starting Java with the arguments $JAVA_OPTS" | |
java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment