Skip to content

Instantly share code, notes, and snippets.

@fabri1983
Last active September 11, 2019 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabri1983/eaac4470dc2cc638aa009094ef56d5a1 to your computer and use it in GitHub Desktop.
Save fabri1983/eaac4470dc2cc638aa009094ef56d5a1 to your computer and use it in GitHub Desktop.
Multi stage Docker file for image creation based on Alpine Linux, Tomcat native, OpenJDK JRE, and FFMPEG 4.x. WAR file has to be decompressed outside.
# OpenJDK 12 alpine jdk/jre uses alpine 3.10.
# Visit https://github.com/AdoptOpenJDK/openjdk-docker/blob/master/12/jre/alpine/Dockerfile.hotspot.releases.full
######################################################################################################
FROM alpine:3.10 AS STAGING-TOMCAT
LABEL maintainer="fabri1983dockerid"
############# INSTALL NATIVE TOMCAT #############
ENV CATALINA_HOME=/opt/tomcat \
TOMCAT_MAJOR="8" \
TOMCAT_VERSION="8.5.43" \
# default JVM installation when downloaded as a package
TEMP_JAVA_HOME=/usr/lib/jvm/default-jvm
# Download OpenJDK 11 (12 is not available), Tomcat, and then Build tc-native
RUN apk add --no-cache --virtual .my-build-deps apr-dev openssl-dev openjdk11-jdk make g++ && \
cd /tmp && \
wget -O apache-tomcat.tar.gz http://archive.apache.org/dist/tomcat/tomcat-${TOMCAT_MAJOR}/v${TOMCAT_VERSION}/bin/apache-tomcat-${TOMCAT_VERSION}.tar.gz && \
tar -C /opt -xf apache-tomcat.tar.gz && \
ln -s /opt/apache-tomcat-$TOMCAT_VERSION $CATALINA_HOME && \
cd $CATALINA_HOME/bin && \
tar -xf tomcat-native.tar.gz && \
rm -f tomcat-native.tar.gz && \
cd tomcat-native-*-src/native && \
./configure --with-java-home=$TEMP_JAVA_HOME --prefix=$CATALINA_HOME && \
make && \
make install && \
make clean && \
rm -rf /tmp/* && \
# Remove added packages
apk del --purge .my-build-deps && \
rm -rf /var/cache/apk/*
#################################################
################ MINIMAL TOMCAT #################
# Minimal Tomcat: remove all default webapps
RUN rm -rf \
${CATALINA_HOME}/webapps/ROOT \
${CATALINA_HOME}/webapps/docs \
${CATALINA_HOME}/webapps/examples \
${CATALINA_HOME}/webapps/host-manager \
${CATALINA_HOME}/webapps/manager
#################################################
######################################################################################################
FROM alpine:3.10 AS STAGING-WAR
ARG DEPENDENCIES=docker-workdir
LABEL maintainer="fabri1983dockerid"
################# STAGING WAR ###################
# Create target folder
RUN mkdir -p /staging/app/
# Stage dependencies and classes
COPY ${DEPENDENCIES}/META-INF /staging/app/META-INF
COPY ${DEPENDENCIES}/WEB-INF /staging/app/WEB-INF
COPY ${DEPENDENCIES}/general-error.jsp /staging/app/
COPY ${DEPENDENCIES}/index.jsp /staging/app/
COPY ${DEPENDENCIES}/log4j2.xml /staging/app/
#################################################
######################################################################################################
FROM adoptopenjdk/openjdk12:alpine-jre
ARG API_NAME
LABEL maintainer="fabri1983dockerid"
ENV CATALINA_HOME=/opt/tomcat
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CATALINA_HOME/lib
# Download ffmpeg as a package (last version always, otherwise you need to build from source)
# Download libs used by Tomcat native
RUN apk add --no-cache ffmpeg apr openssl && \
rm -rf /var/cache/apk/*
# Copy from symbolic link created in previous image
COPY --from=STAGING-TOMCAT $CATALINA_HOME $CATALINA_HOME
# Copy staged files into Tomcat's webapp folder
COPY --from=STAGING-WAR /staging/app ${CATALINA_HOME}/webapps/${API_NAME}
EXPOSE 8080
ENTRYPOINT exec ${CATALINA_HOME}/bin/catalina.sh run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment