Tomcat Container

From Dogtag
Jump to: navigation, search

Pulling Tomcat Image

$ docker pull tomcat

Running Tomcat Container

To run Tomcat container:

$ docker run \
  --name tomcat \
  --rm \
  -p 8080:8080 \
  tomcat

To access the container:

$ docker exec -ti tomcat bash

Deployment

To install JAR file:

$ docker cp <JAR file> tomcat:/usr/local/tomcat/lib

To install WAR file:

$ docker cp <WAR file> tomcat:/usr/local/tomcat/webapps/<context>.war

OpenShift

To deploy Tomcat on OpenShift:

$ oc new-app tomcat

To expose Tomcat with a default hostname:

$ oc expose svc/tomcat

To expose Tomcat with a proper hostname:

$ oc expose svc/tomcat --name server.example.com --hostname server.example.com

Then create a CNAME record:

server.example.com. IN CNAME <default hostname>.

Building Tomcat Image

Create the following Dockerfile:

FROM fedora:30

EXPOSE 8080

RUN dnf install -y tomcat && dnf clean all

USER tomcat

ENTRYPOINT [ \
    "/usr/lib/jvm/jre/bin/java", \
    "-Djavax.sql.DataSource.Factory=org.apache.commons.dbcp.BasicDataSourceFactory", \
    "-classpath", \
    "/usr/share/tomcat/bin/bootstrap.jar:/usr/share/tomcat/bin/tomcat-juli.jar:/usr/lib/java/commons-daemon.jar", \
    "-Dcatalina.base=/usr/share/tomcat", \
    "-Dcatalina.home=/usr/share/tomcat", \
    "-Djava.endorsed.dirs=", \
    "-Djava.io.tmpdir=/var/cache/tomcat/temp", \
    "-Djava.util.logging.config.file=/usr/share/tomcat/conf/logging.properties", \
    "-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager", \
    "org.apache.catalina.startup.Bootstrap", \
    "start" \
]

To build the image:

$ docker build -t tomcat .

To create the container:

$ docker run \
    --name tomcat \
    --tmpfs /tmp \
    --tmpfs /run \
    --publish 8080:8080 \
    tomcat

References