Skip to content

Commit a6798ff

Browse files
committed
Update Base tomcat image
1 parent 1ef1e8a commit a6798ff

File tree

2 files changed

+150
-0
lines changed

2 files changed

+150
-0
lines changed

.dockerignore

Whitespace-only changes.

Dockerfile-tomcat-jre

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
# docker build -t prasad1210/tomcat-custom:9.0.35.1-alpine-11.0.7 . -f Dockerfile-tomcat-jre --no-cache
2+
FROM alpine:latest AS stage-0
3+
RUN set -eux;\
4+
apk --no-cache --virtual add openjdk11
5+
#--repository=http://dl-cdn.alpinelinux.org/alpine/edge/community
6+
WORKDIR /usr/lib/jvm/default-jvm/jre/bin/
7+
RUN set -eux;\
8+
./jlink --output jre --compress=2 --no-header-files --no-man-pages --module-path ../jmods --add-modules java.management,java.management.rmi,java.naming,java.net.http,java.prefs,java.rmi,java.scripting,java.se,java.security.jgss,java.security.sasl,java.smartcardio,java.sql,java.sql.rowset,java.transaction.xa,java.xml,java.xml.crypto
9+
10+
11+
12+
FROM alpine:latest
13+
14+
MAINTAINER Prasad CH<[email protected]>
15+
16+
# Install dependencies:
17+
# ca-certificates-cacert-20191127-r1 x86_64: for certificate management to support SSL
18+
# openjdk11-jre-11.0.5_p10-r0: OpenJDK built by Simon Frankenberger <[email protected]> from https://hg.openjdk.java.net/jdk-updates/jdk11u
19+
# fontconfig-2.13.1-r2 x86_64 : For supporting UI/ Fonts for reporting purposes
20+
# freetype-2.10.1-r0 x86_64: To support freetype fonts
21+
# Tomcat: Run a Java Container
22+
# Additional dependencies for system commands used by above components:
23+
# musl-1.1.24-r2 x86_64 {musl} (MIT) [installed]
24+
# libbz2-1.0.8-r1 x86_64 {bzip2} (bzip2-1.0.6) [installed]
25+
# zlib-1.2.11-r3 x86_64 {zlib} (Zlib) [installed]
26+
# apk-tools-2.10.5-r0 x86_64 {apk-tools} (GPL2) [installed]
27+
# musl-utils-1.1.24-r2 x86_64 {musl} (MIT BSD GPL2+) [installed]
28+
# libssl1.1-1.1.1g-r0 x86_64 {openssl} (OpenSSL) [installed]
29+
# alpine-baselayout-3.2.0-r3 x86_64 {alpine-baselayout} (GPL-2.0-only) [installed]
30+
# libpng-1.6.37-r1 x86_64 {libpng} (Libpng) [installed]
31+
# ca-certificates-20191127-r2 x86_64 {ca-certificates} (MPL-2.0 GPL-2.0-or-later) [installed]
32+
# alpine-keys-2.1-r2 x86_64 {alpine-keys} (MIT) [installed]
33+
# busybox-1.31.1-r9 x86_64 {busybox} (GPL-2.0-only) [installed]
34+
# libuuid-2.34-r1 x86_64 {util-linux} (GPL-2.0 GPL-2.0-or-later LGPL-2.0-or-later BSD Public-Domain) [installed]
35+
# scanelf-1.2.4-r0 x86_64 {pax-utils} (GPL-2.0-only) [installed]
36+
# libc-utils-0.7.2-r0 x86_64 {libc-dev} (BSD) [installed]
37+
# libtls-standalone-2.9.1-r0 x86_64 {libtls-standalone} (ISC) [installed]
38+
# ssl_client-1.31.1-r9 x86_64 {busybox} (GPL-2.0-only) [installed]
39+
# expat-2.2.9-r1 x86_64 {expat} (MIT) [installed]
40+
# libcrypto1.1-1.1.1g-r0 x86_64 {openssl} (OpenSSL) [installed]
41+
#
42+
43+
# https://adoptopenjdk.net/installation.html#x64_linux-jre
44+
RUN mkdir -p /usr/lib/jvm
45+
COPY --from=stage-0 /usr/lib/jvm/default-jvm/jre/bin/jre /usr/lib/jvm/default-jre
46+
ENV PATH=/usr/lib/jvm/default-jre/bin:$PATH
47+
ENV JAVA_HOME=/usr/lib/jvm/default-jre/
48+
ENV JAVA_VERSION=11.0.7+11-alpine-r1
49+
50+
RUN set -eux;\
51+
apk update \
52+
# Now Add Support for cacerts
53+
# https://hackernoon.com/alpine-docker-image-with-secured-communication-ssl-tls-go-restful-api-128eb6b54f1f
54+
&& apk add --no-cache ca-certificates\
55+
56+
# Now Add Support for UI/Font configurations
57+
# java.lang.UnsatisfiedLinkError: /usr/local/openjdk-11/lib/libfontmanager.so: libfreetype.so.6: cannot open shared object file: No such file or directory
58+
# java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11FontManager
59+
# https://github.com/docker-library/openjdk/pull/235#issuecomment-424466077
60+
\fontconfig freetype\
61+
62+
&& rm -rf /var/cache/apk/*
63+
64+
# COPY ./org-cacert-bundle.crt /usr/local/share/ca-certificates/mycert.crt
65+
# COPY --from stage-0 /usr/local/share/ca-certificates /usr/local/share/ca-certificates
66+
RUN set -eux;\
67+
chmod 755 /usr/local/share/ca-certificates\
68+
&& update-ca-certificates\
69+
# Load Organisational fonts
70+
&& mkdir -p /usr/share/fonts/default/TrueType
71+
# COPY --from stage-0 /tmp/custom-fonts/ /usr/share/fonts/default/TrueType
72+
73+
74+
# Inspired from https://github.com/docker-library/tomcat/blob/d570ad0cee10e4526bcbb03391b2c0e322b59313/9.0/jdk11/openjdk-slim/Dockerfile
75+
ENV CATALINA_HOME /usr/local/tomcat
76+
ENV PATH $CATALINA_HOME/bin:$PATH
77+
RUN mkdir -p "$CATALINA_HOME"
78+
79+
WORKDIR $CATALINA_HOME
80+
81+
# let "Tomcat Native" live somewhere isolated
82+
ENV TOMCAT_NATIVE_LIBDIR $CATALINA_HOME/native-jni-lib
83+
ENV LD_LIBRARY_PATH ${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$TOMCAT_NATIVE_LIBDIR
84+
85+
# see https://www.apache.org/dist/tomcat/tomcat-$TOMCAT_MAJOR/KEYS
86+
# see also "update.sh" (https://github.com/docker-library/tomcat/blob/master/update.sh)
87+
ENV GPG_KEYS 05AB33110949707C93A279E3D3EFE6B686867BA6 07E48665A34DCAFAE522E5E6266191C37C037D42 47309207D818FFD8DCD3F83F1931D684307A10A5 541FBE7D8F78B25E055DDEE13C370389288584E7 61B832AC2F1C5A90F0F9B00A1C506407564C17A3 79F7026C690BAA50B92CD8B66A3AD3F4F22C4FED 9BA44C2621385CB966EBA586F72C284D731FABEE A27677289986DB50844682F8ACB77FC2E86E29AC A9C5DF4D22E99998D9875A5110C01C5A2F6059E7 DCFD35E0BF8CA7344752DE8B6FB21E8933C60243 F3A04C595DB5B6A5F1ECA43E3B7BBB100D811BBE F7DA48BB64BCB84ECBA7EE6935CD23C10D498E23
88+
89+
ENV TOMCAT_MAJOR 9
90+
ENV TOMCAT_VERSION 9.0.35
91+
ENV TOMCAT_DOWNLOAD_URL https://downloads.apache.org/tomcat/tomcat-9/v9.0.35/bin/apache-tomcat-9.0.35.tar.gz
92+
ENV TOMCAT_SHA512 0db27185d9fc3174f2c670f814df3dda8a008b89d1a38a5d96cbbe119767ebfb1cf0bce956b27954aee9be19c4a7b91f2579d967932207976322033a86075f98
93+
94+
# Install Tomcat
95+
RUN set -eux;\
96+
wget "$TOMCAT_DOWNLOAD_URL"\
97+
&& echo "$TOMCAT_SHA512 *apache-tomcat-9.0.35.tar.gz" | sha512sum -c -\
98+
&& mkdir -p /usr/local/tomcat\
99+
&& tar -xf apache-tomcat-9.0.35.tar.gz --strip-components=1\
100+
&& rm bin/*.bat\
101+
&& rm apache-tomcat-9.0.35.tar.gz*\
102+
&& rm -rf webapps\
103+
&& mkdir webapps\
104+
&& find ./bin/ -name '*.sh' -exec sed -ri 's|^#!/bin/sh$|#!/usr/bin/env sh|' '{}' + \
105+
&& chmod -R +rX . \
106+
&& chmod 777 logs temp work
107+
108+
#Create config and log folders
109+
RUN mkdir -p ${CATALINA_HOME}/conf/ ${CATALINA_HOME}/logs/ ${CATALINA_HOME}/config/
110+
111+
# Copy Custom init scripts if required
112+
# COPY bin/setenv.sh ${CATALINA_HOME}/bin/setenv.sh
113+
# RUN chmod 750 ${CATALINA_HOME}/bin/setenv.sh
114+
115+
# Remove default Tomcat installation files
116+
RUN rm -rf ${CATALINA_HOME}/webapps/*
117+
# Copy any additional organisational default files to override tomcat default config files
118+
119+
120+
# User Management
121+
# Add custom group tomcat with 61000 as a groupid to avoid conflicts with any existing groups
122+
RUN addgroup -g 61000 tomcat
123+
124+
# Add custom user tomcat with same uid 61000 as gid to avoid conflict with exist user
125+
# User with no home directory, no password, group as tomcat and username as tomcat
126+
RUN adduser -H -D -G tomcat -u 61000 tomcat
127+
128+
# We put the tomcat user as the owner of the folder of tomcat to limit access to tomcat process on container resources
129+
RUN set -eux;\
130+
chown -R tomcat:tomcat /usr/local/tomcat\
131+
# Users cannot modify configuration of tomcat
132+
&& chmod -R g+r /usr/local/tomcat/conf\
133+
# Users can modify the other folders
134+
&& chmod -R g+w /usr/local/tomcat/logs\
135+
&& chmod -R g+w /usr/local/tomcat/temp\
136+
&& chmod -R g+w /usr/local/tomcat/webapps\
137+
&& chmod -R g+w /usr/local/tomcat/work\
138+
# Activate the sticky-bit for new files keep permissions defined:
139+
&& chmod -R g+s /usr/local/tomcat/conf\
140+
&& chmod -R g+s /usr/local/tomcat/logs\
141+
&& chmod -R g+s /usr/local/tomcat/temp\
142+
&& chmod -R g+s /usr/local/tomcat/webapps\
143+
&& chmod -R g+s /usr/local/tomcat/work
144+
145+
# Set user as tocmat by uid to be compatible with kubernetes psp
146+
USER 61000
147+
148+
EXPOSE 8080
149+
150+
CMD ["catalina.sh", "run"]

0 commit comments

Comments
 (0)