Skip to content

Instantly share code, notes, and snippets.

@Thanajade
Forked from nik-sta/Dockerfile
Last active July 5, 2022 06:26
Show Gist options
  • Save Thanajade/8aeeb12a39ecfdb6fa905664c2f352bd to your computer and use it in GitHub Desktop.
Save Thanajade/8aeeb12a39ecfdb6fa905664c2f352bd to your computer and use it in GitHub Desktop.
Layered Production-ready Dockerfile for Spring Boot Applications
# Making here use of a docker multi-stage build
# https://docs.docker.com/develop/develop-images/multistage-build/
# Build-time container
FROM eclipse-temurin:17.0.3_7-jdk-alpine as builder
ARG JAR_FILE
WORKDIR application
COPY $JAR_FILE application.jar
COPY build_application.sh ./
RUN sh build_application.sh
# Run-time container
FROM alpine:3.16.0
ARG APP_NAME=app
ARG USER=exie
ARG GROUP=party
ARG LOG_FOLDER=/srv/app/logs
ENV APP=$APP_NAME \
JAVA_HOME=/opt/java \
PATH="${JAVA_HOME}/bin:${PATH}"
## Adding programs for operation
RUN apk update && \
apk --no-cache add dumb-init curl jq && \
rm -rf /var/cache/apk/*
WORKDIR /srv/$APP
COPY run_application.sh /etc
RUN addgroup -S $GROUP && \
adduser -S -D -H $USER -G $GROUP && \
mkdir -p $LOG_FOLDER && \
chgrp $GROUP $LOG_FOLDER && \
chmod g+rwx $LOG_FOLDER && \
chmod +x /etc/run_application.sh
## Application-specif created JRE
COPY --from=builder /opt/java-runtime $JAVA_HOME
## Spring Boot Layers
COPY --from=builder application/spring-boot-loader/ ./
COPY --from=builder application/dependencies/ ./
COPY --from=builder application/snapshot-dependencies/ ./
COPY --from=builder application/application/ ./
USER $USER
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
CMD ["/etc/run_application.sh"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment