Dockerfile for Tomcat/JDK¶
This page documents the creation of a Docker image containing both the Java Development Kit (JDK) and Apache Tomcat, based on a CentOS 7 base image^[600-developer__docker__Dockerfile__Dockerfile-01.md]。
Base Image and Dependencies¶
The Dockerfile uses centos:7 as the base image^[600-developer__docker__Dockerfile__Dockerfile-01.md]。 It requires two primary installation artifacts to be present in the build context:
* jdk-8u91-linux-x64.tar.gz: A local archive for the JDK^[600-developer__docker__Dockerfile__Dockerfile-01.md]。
* Apache Tomcat 8.5.35: Retrieved via wget during the build process^[600-developer__docker__Dockerfile__Dockerfile-01.md]。
Additionally, the wget utility is installed using yum to facilitate the download of Tomcat^[600-developer__docker__Dockerfile__Dockerfile-01.md]。
Dockerfile Configuration¶
The build process involves extracting the JDK and Tomcat archives and configuring the necessary environment variables^[600-developer__docker__Dockerfile__Dockerfile-01.md]。
Environment Variables
* JAVA_HOME is set to the JDK installation path (/jdk1.8.0_91 in the example)^[600-developer__docker__Dockerfile__Dockerfile-01.md]。
* PATH is updated to include $JAVA_HOME/bin^[600-developer__docker__Dockerfile__Dockerfile-01.md]。
Runtime Configuration
* Command: The container is configured to run Tomcat automatically using the catalina.sh run command^[600-developer__docker__Dockerfile__Dockerfile-01.md]。
* Ports: Port 8080 is exposed to allow access to the Tomcat service^[600-developer__docker__Dockerfile__Dockerfile-01.md]。
Build and Run Commands¶
To create the image from the Dockerfile, run the following command in the directory containing the Dockerfile and the JDK tarball^[600-developer__docker__Dockerfile__Dockerfile-01.md]:
docker build -t mytomcat . --no-cache
To run the container and map the container's port 8080 to the host's port 8080^[600-developer__docker__Dockerfile__Dockerfile-01.md]:
docker run -p 8080:8080 mytomcat
To enter the container for debugging purposes^[600-developer__docker__Dockerfile__Dockerfile-01.md]:
docker run -it mytomcat /bin/bash
Related Concepts¶
- [[Docker Registry Server]]
- [[流程化筆記]]
Sources¶
^[600-developer__docker__Dockerfile__Dockerfile-01.md]