ARG) for Tomcat versioning, and demonstrate how to override it at build time.
Table of Contents
- Prerequisites
- Clone the Repository
- Reviewing the Dockerfile
- Dockerfile Instruction Reference
- Building and Running the Default Image
- Building with a Custom Tomcat Version
- Links and References
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 ourDockerfile:
Reviewing the Dockerfile
Below is the completeDockerfile. It installs OpenJDK 8, downloads Tomcat into /opt/tomcat, sets permissions, and deploys a sample WAR file.
Dockerfile Instruction Reference
| Instruction | Description | Example |
|---|---|---|
FROM | Base image | centos:7 |
ARG | Build-time variable; default Tomcat version | ARG tomcat_version=8.5.6 |
RUN | Execute shell commands (install, create, download) | yum install -y java-1.8.0-openjdk wget |
WORKDIR | Set working directory | /opt/tomcat/webapps |
EXPOSE | Document container port | 8080 |
CMD | Default command when container starts | ["/opt/tomcat/bin/catalina.sh","run"] |
Building and Running the Default Image
Build with the default Tomcat version (8.5.6):
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 overridetomcat_version at build time to use any release from the Apache Tomcat Archive:
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.