使用Jenkins部署Maven项目至Docker Tomcat后Web应用无法显示
Let’s break down the possible issues and fixes step by step—since Tomcat is running but your app isn’t showing up, the problem likely ties to deployment paths, port mapping, or war file handling.
1. Fix the Tomcat Webapps Directory Typo
First, I noticed you mentioned the war is placed at /usr/local/tomcat/webapp/webapp.war—that’s a critical typo! Tomcat’s default deployment directory is webapps (plural, with an 's'). If your Dockerfile copied the war to the singular webapp folder, Tomcat won’t scan this directory for deployments at all.
- Fix: Update your Dockerfile’s COPY command to target the correct path:
COPY target/webapp.war /usr/local/tomcat/webapps/
2. Verify Host-to-Container Port Mapping
Tomcat runs on port 8080 inside the container by default. To access it via port 8181 on your host, you must explicitly map these ports when starting the container.
- Check your Jenkins pipeline’s docker run command: It should include the
-p 8181:8080flag. For example:
If you missed this mapping, even a healthy Tomcat container won’t be reachable via port 8181 on your host.docker run -d -p 8181:8080 --name tomcat-hello-world your-image-tag
3. Confirm the War File Is Deployed Properly
Tomcat automatically unpacks valid war files into a matching directory (e.g., webapp.war → webapp/). If this didn’t happen, either the war is corrupted or Tomcat’s auto-deploy settings are disabled.
- Check container logs for deployment errors:
Look for lines like "Failed to deploy application" or "Invalid war file"—these will point to issues with the war itself.docker exec -it <your-container-id> tail -f /usr/local/tomcat/logs/catalina.out - Verify auto-deploy is enabled: Inside the container, check Tomcat’s
conf/server.xmlfile. The Host element should have these settings:
If<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">unpackWARsorautoDeployare set tofalse, Tomcat won’t process the war file automatically.
4. Use the Correct Access URL
If your war is named webapp.war, Tomcat deploys it under the context path /webapp. That means you need to access:
http://<your-host-ip>:8181/webapp/
Instead of just http://<your-host-ip>:8181/ (which loads Tomcat’s default ROOT welcome page).
- Pro tip for root access: If you want your app to load at the root path, rename your war file to
ROOT.warbefore copying it to thewebappsdirectory. You can adjust this in your Maven build or Dockerfile.
5. Validate Jenkins Pipeline Workflow
Double-check that your Jenkinsfile is correctly passing the built war to the Docker build context:
- Ensure
mvn clean packageoutputs the war totarget/webapp.war(match this path in your Dockerfile’s COPY command). - If using a Docker agent in Jenkins, confirm the workspace files (including the war) are accessible to the Docker build process.
内容的提问来源于stack exchange,提问作者kush shah

