You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Jenkins部署Maven项目至Docker Tomcat后Web应用无法显示

Troubleshooting Guide: Maven Hello-World App Not Showing in Dockerized Tomcat (8181 Port)

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:8080 flag. For example:
    docker run -d -p 8181:8080 --name tomcat-hello-world your-image-tag
    
    If you missed this mapping, even a healthy Tomcat container won’t be reachable via port 8181 on your host.

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:
    docker exec -it <your-container-id> tail -f /usr/local/tomcat/logs/catalina.out
    
    Look for lines like "Failed to deploy application" or "Invalid war file"—these will point to issues with the war itself.
  • Verify auto-deploy is enabled: Inside the container, check Tomcat’s conf/server.xml file. The Host element should have these settings:
    <Host name="localhost"  appBase="webapps"
          unpackWARs="true" autoDeploy="true">
    
    If unpackWARs or autoDeploy are set to false, 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.war before copying it to the webapps directory. 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 package outputs the war to target/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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 04:20:31