Deploying Apache Tomcat 8 on Top of Red Hat UBI 8 and Java 11
UBI (Universal Base Image) 8 is an OCI-compliant container base operating system images with complementary runtime languages and packages that are freely redistributable. Like previous base images, they are built from portions of Red Hat Enterprise Linux. UBI images can be obtained from the Red Hat container catalog, and be built and deployed anywhere.
On this sample, im trying to create a Apache Tomcat 8 (version 8.0.5 to be precise), and deploy it on top on a UBI8 base image, with JDK 11 installed on it. And after that, i’ll deploy a simple hello world java application on top of Tomcat 8.
So, lets start with a simple java application,
git clone https://github.com/edwin/hello-world-jboss-eap.git
and build it into a war file
mvn clean package
create a Dockerfile to install Apache Tomcat 8 and copy our created war file into Tomcat’s webapps folder
FROM registry.access.redhat.com/ubi8/openjdk-11 RUN curl -k https://archive.apache.org/dist/tomcat/tomcat-8/v8.0.5/bin/apache-tomcat-8.0.5.tar.gz -L -o "/tmp/apache-tomcat-8.0.5.tar.gz" \ && tar -xf "/tmp/apache-tomcat-8.0.5.tar.gz" -C /deployments/ ; # remove it manually, otherwise it will create an error "Endorsed standards and standalone APIs in modular form will be supported via the concept of upgradeable modules" RUN sed -i 's/endorsed/e/g' /deployments/apache-tomcat-8.0.5/bin/catalina.sh COPY HelloWorld.war /deployments/apache-tomcat-8.0.5/webapps/HelloWorld.war EXPOSE 8080 CMD ["/deployments/apache-tomcat-8.0.5/bin/catalina.sh", "run"]
Build it,
docker build -t ubi8-with-tomcat8 .
And run,
docker run -p 8080:8080 ubi8-with-tomcat8
We can see the result on browser,
If we want to create an HTTPS application, then there will be some modification needed. First we need to create a keystore, and give changeit
as its password.
keytool -genkey -alias tomcat -keyalg RSA -keystore my-release-key.keystore
Edit Tomcat’s server.xml, adding below line
<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol" maxThreads="150" SSLEnabled="true" scheme="https" secure="true" keystoreFile="/deployments/my-release-key.keystore" keystorePass="changeit" clientAuth="false" sslProtocol="TLS" />
Do some minor modification on Dockerfile,
FROM registry.access.redhat.com/ubi8/openjdk-11 RUN curl -k https://archive.apache.org/dist/tomcat/tomcat-8/v8.0.5/bin/apache-tomcat-8.0.5.tar.gz -L -o "/tmp/apache-tomcat-8.0.5.tar.gz" \ && tar -xf "/tmp/apache-tomcat-8.0.5.tar.gz" -C /deployments/ ; # remove it manually, otherwise it will create an error "Endorsed standards and standalone APIs in modular form will be supported via the concept of upgradeable modules" RUN sed -i 's/endorsed/e/g' /deployments/apache-tomcat-8.0.5/bin/catalina.sh COPY server.xml /deployments/apache-tomcat-8.0.5/conf/server.xml COPY my-release-key.keystore /deployments/my-release-key.keystore COPY HelloWorld.war /deployments/apache-tomcat-8.0.5/webapps/HelloWorld.war EXPOSE 8080 8443 CMD ["/deployments/apache-tomcat-8.0.5/bin/catalina.sh", "run"]
Open browser to see the result,
Have fun with UBI8