Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Note
titlePrerequisites

In addition to a Dockerfile, the following files are required to build the Docker image:

  • <service_name>.war - a deployable archive of the desired web application, e.g., webapp.war, collaborator.war, or admin.war.
  • <install_root>/WebAppPlatform/shared/conf/logback.xml - the logging configuration file. To learn how to configure data logging, see Configuring data logging.
  • <install_root>/WebAppPlatform/shared/conf/webappplatform.properties - the file with Web Application Platform configuration properties.
  • you You may also need additional files, like email or document export templates that need to be copied to the web container.

...

Note

Note that running multiple Docker images without resource limitation can consume too much of the host machine’s memory and cause "out of memory" kills. For more information on how to set resource constraints for a Docker container, refer to https://docs.docker.com/config/containers/resource_constraints/.


Here is a sample a Dockerfile that can be used to build the Docker image:

Code Block
FROM tomcat:9-jdk17-openjdk10.1.8-jre17-temurin-jammy

ARG TOMCAT_HOME_DIR=/usr/local/tomcat
ARG SET_ENV_FILE=/usr/local/tomcat/bin/setenv.sh
ARG USER_UID=5000
ARG USER_GID=${USER_UID}

COPY logback.xml ${TOMCAT_HOMEDIR}/shared/conf/
COPY webappplatform.properties ${TOMCAT_HOMEDIR}/shared/conf/
COPY <service_name>.war ${TOMCAT_HOMEDIR}/webapps/

RUN sed -i "s|shared\.loader=*$|shared\.loader=\"\${catalina.base}/shared/conf\"|" ${TOMCAT_HOMEDIR}/conf/catalina.properties && \
    echo 'export JAVA_OPTS="$JAVA_OPTS ${WEBAPP_PROPERTIES}"' >> ${SET_ENV_FILE} && \
    chmod o+x ${SET_ENV_FILE} && \
    groupadd --gid ${USER_GID} tomcat && \
    useradd -r --uid ${USER_UID} --gid ${USER_GID} -s /sbin/nologin -d ${TOMCAT_DIR} -c "Tomcat user" tomcat && \
    chown -R tomcat:tomcat ${TOMCAT_DIR} && \
    chown -R root:root ${TOMCAT_DIR}/bin/*.sh && \
    rm -rf webapps.dist

USER tomcat

EXPOSE 8080

CMD ["catalina.sh", "run"]


Instructions in the Dockerfile may be written in several ways depending on your particular needs and preferences. The table below lists script statements you can use with descriptions and the indication of whether the script part is required or optional.

Script statementRequired or optionalDescription

FROM tomcat:

9-jdk17-openjdk

10.1.8-jre17-temurin-jammy

Required

In the FROM part where the base image needs to be specified, Tomcat should be selected as the base image and its version has to be compatible with the version of the web application code.

ARG TOMCAT_
HOME
DIR=/usr/local/tomcatOptionalAn argument
that is
used as an intermediary variable to store the Tomcat
home
directory location. The location may
be different
differ depending on a particular base image used in the FROM part. This argument is introduced for convenience since further instructions reference the Tomcat
home
directory location multiple times.
ARG SET_ENV_FILE=/usr/local/tomcat/bin/setenv.shOptionalThe path to the setenv.sh file which is used to set JAVA options.
ARG USER_UID=5000Required

The user ID that will be assigned to the Tomcat user (for Tomcat to be run as a Tomcat user and not a root).

ARG USER_GID=${USER_UID}RequiredAn argument used to set a user group for the Tomcat user.

COPY logback.xml ${TOMCAT_

HOME

DIR}/shared/conf/

Optional (recommended)

Since Web Application Platform uses logback as the logging framework, there should be its configuration file available in the classpath. This command copies the logging configuration into the folder that will be included in the classpath.

Note that it is possible to use other names for the configuration file. In this case, the script should be updated to reference another file. It is possible to omit the configuration file but it is not recommended.

COPY webappplatform.properties ${TOMCAT_

HOME

DIR}/shared/conf/

Optional

This command copies the properties file to the folder that is present in the classpath. If it is not copied, then an alternative solution must be used to reference the properties file. To learn about alternative options, see Passing properties to services.

COPY <service_name>.war ${TOMCAT_

HOME

DIR}/webapps/

Required

This command copies the web application to the Tomcat deployment folder.

Note that you can put multiple web applications in the same docker image. To do that, add a separate command for each .war file.

RUN sed -i "s|shared\.loader=*$|shared\.loader=\"\${catalina.base}/shared/conf\"|" ${TOMCAT_DIR}/conf/catalina.properties && \ echo 'export JAVA_OPTS="$JAVA_OPTS ${WEBAPP_PROPERTIES}"' >> ${SET_ENV_FILE} && \ chmod o+x ${SET_ENV_FILE} && \ groupadd --gid ${USER_GID} tomcat && \ useradd -r --uid ${USER_UID} --gid ${USER_GID} -s /sbin/nologin -d ${TOMCAT_DIR} -c "Tomcat user" tomcat && \ chown -R tomcat:tomcat ${TOMCAT_DIR} && \ chown -R root:root ${TOMCAT_DIR}/bin/*.sh && \ rm -rf webapps.dist

Required if any additional files need to be in the classpath

This command updates the Tomcat configuration to include ${TOMCAT_

HOME

DIR}/shared/conf in the classpath. In addition, it sets JAVA_OPTS and assigns permissions and a group to the Tomcat user.

USER tomcatRequiredSpecify the user which will be used to start Tomcat.

EXPOSE 8080

Required

The value should correspond to the one

which

that is used by Tomcat to deploy the web application. You can use port 8080 or 8443 if SSL is needed.

CMD [“catalina.sh”, “run”]

Required

A command used to run the Tomcat server.


Here is a sample command to build the Docker image:

...


The provided build command will work only if the Dockerfile script and all the files referenced in the script (in this case <service_name>.war, logback.xml, and webappplatform.properties) are stores stored in the current directory. To build Docker images using non-default file locations, consult the Docker documentation.

...