Apache Tomcat container with Podman

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

Introduction

The Apache Tomcat container software is developed in an open-source and participatory environment under the Apache License version 2. The Apache Tomcat project is intended to be a collaboration of the best-of-breed developers from around the world. We invite you to participate in this open development project. To learn more about getting involved, click here or keep reading. You can also check Tomcat 10 installation tutorial.

Pull an image from registry

# podman search tomcat --filter=is-official
# podman pull docker.io/library/tomcat

Create Apache tomcat container pod

# podman pod create --name tomcatapp -p 8080:8080 --network bridge

Run a container based on Tomcat image downloaded

Here we have initiated a container for the tomcat image and exposed the port 8080 of the tomcat container on port 8080 of localhost using port forwarding. The list of all containers that are available can be shown using the ps option for podman.

# podman run --pod tomcatapp --name tomcat-server -d tomcat:9.0
# podman ps

Fixing error 404

Here is the solution to fix the issue.

# podman exec -it tomcat-server /bin/bash
# mv webapps webapps2
# mv webapps.dist/ webapps
# exit

Persisting your application

If you remove the container all your data and configurations will be lost, and the next time you run the image the database will be reinitialized. To avoid this loss of data, you should mount a volume that will persist even after the container is removed.

For persistence, you should mount a directory at the  /usr/local/tomcat  path. If the mounted directory is empty, it will be initialized on the first run.

The default Tomcat environment in the image is:

CATALINA_BASE:   /usr/local/tomcat
CATALINA_HOME:   /usr/local/tomcat
CATALINA_TMPDIR: /usr/local/tomcat/temp
JRE_HOME:        /usr
CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar

The configuration files are available in /usr/local/tomcat/conf/. No user is included in the “manager-GUI” role to operate the “/manager/html” application. If you wish to use this app, you must define such a user in tomcat-users.xml.

Apache Tomcat image maintainers have chosen not to enable the default applications as a security precaution, but with two custom configuration files and overriding the Docker command, it is possible to boot Tomcat with a fully functional manager application.

This post provided example configuration files and the podman command to restore the default applications before running Tomcat.

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"
Neil
Neil
Treat your password like your toothbrush. Don’t let anybody else use it, and get a new one every six months.

1 COMMENT

  1. Unfortinately I have to assume this article is very, very old and obsolete.

    Why??? Because YOU DON’T DATE YOUR ARTICLES! I have no way of knowing how ‘recent’ it is and there are tons of 10-year-old articles out there.

    Also this doesn’t work – it does *not* initialize – it just gives you an empty /usr/local/tomcat and catalina won’t run:

    “For persistence, you should mount a directory at the /usr/local/tomcat path. If the mounted directory is empty, it will be initialized on the first run.”

    Example:

    âžś pman ls tomcat
    âžś pman podman container rm tomcat-server
    abe95643007ca3a080b1cc8e772cb894bad014c8a608e4692972e80f4020dad0
    âžś pman podman run –pod tomcatapp –name tomcat-server -v /home3/greg/pman/tomcat:/usr/local/tomcat -d tomcat:9.0
    Error: runc: container_linux.go:380: starting container process caused: exec: “catalina.sh”: executable file not found in $PATH: OCI runtime attempted to invoke a command that was not found
    âžś pman ls tomcat
    âžś pman

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook