Skip to main content
In this tutorial, you’ll learn how to create a Docker image for Apache Tomcat on a CentOS 7 base. We’ll introduce a build-time argument (ARG) for Tomcat versioning, and demonstrate how to override it at build time.

Table of Contents


Prerequisites

  • Docker Engine installed (≥ 19.03)
  • Basic familiarity with Docker commands
  • Internet access to download Tomcat and sample WAR
Ensure you have enough disk space (~500 MB) and proper network connectivity to Apache archives.

Clone the Repository

Get the sample project containing our Dockerfile:

Reviewing the Dockerfile

Below is the complete Dockerfile. It installs OpenJDK 8, downloads Tomcat into /opt/tomcat, sets permissions, and deploys a sample WAR file.

Dockerfile Instruction Reference


Building and Running the Default Image

Build with the default Tomcat version (8.5.6):
Expected output:
Run the container, mapping host port 84 to container port 8080:
Now visit http://<host>:84 in your browser. You should see the Tomcat welcome page for version 8.5.6.

Building with a Custom Tomcat Version

You can override tomcat_version at build time to use any release from the Apache Tomcat Archive:
Sample output:
Verify both images:
Run the new container on port 86:
Now open http://<host>:86 to confirm you’re running Tomcat version 8.5.8.
Always verify that the Tomcat version you specify in --build-arg exists in the archive. Incorrect versions will cause the build to fail.

Watch Video