Last active
December 17, 2024 06:02
-
-
Save karlhillx/9209ca8e319594888e800bc59a7d0d39 to your computer and use it in GitHub Desktop.
Eclipse Temurin JDK/JRE 21 w/ Apache Tomcat 11
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
FROM eclipse-temurin:21-jdk-jammy AS builder | |
# Set environment variables | |
ENV TOMCAT_VERSION=11.0.0-M15 | |
ENV CATALINA_HOME=/usr/local/tomcat | |
# Install necessary tools | |
RUN apt-get update && apt-get install -y wget \ | |
&& rm -rf /var/lib/apt/lists/* | |
# Download and setup Tomcat with security best practices | |
RUN mkdir -p ${CATALINA_HOME} \ | |
&& wget -q https://downloads.apache.org/tomcat/tomcat-11/v${TOMCAT_VERSION}/bin/apache-tomcat-${TOMCAT_VERSION}.tar.gz -O /tmp/tomcat.tar.gz \ | |
&& tar xf /tmp/tomcat.tar.gz -C /tmp \ | |
&& cp -R /tmp/apache-tomcat-${TOMCAT_VERSION}/* ${CATALINA_HOME} \ | |
&& rm -rf /tmp/apache-tomcat-* /tmp/tomcat.tar.gz | |
# Final stage | |
FROM eclipse-temurin:21-jre-jammy | |
LABEL maintainer="Karl Hill <[email protected]>" | |
ENV CATALINA_HOME=/usr/local/tomcat | |
ENV PATH=${CATALINA_HOME}/bin:${PATH} | |
# Copy only necessary files from builder | |
COPY --from=builder ${CATALINA_HOME} ${CATALINA_HOME} | |
# Create non-root user for security | |
RUN groupadd -r tomcat && useradd -r -g tomcat tomcat \ | |
&& chown -R tomcat:tomcat ${CATALINA_HOME} | |
USER tomcat | |
# Health check | |
HEALTHCHECK --interval=30s --timeout=3s \ | |
CMD curl -f http://localhost:8080/ || exit 1 | |
EXPOSE 8080 | |
CMD ["catalina.sh", "run"]CMD ["catalina.sh", "run"] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment