部署WAR到tomcat docker容器后总是得到404

时间:2016-11-21 07:32:27

标签: tomcat docker war

我有一个grails应用程序,已经运行并通过Tomcat8 Jre8上的Elastic Beanstalk部署到AWS。

我现在正试图在多Docker环境中部署它,我有很奇怪的行为。

我使用tomcat:8.0-jre8https://hub.docker.com/r/library/tomcat/)作为容器的图像,并且通过在<tomcat_home>/webapps中放置war文件,该图像上的部署非常简单。另外,我将端口8080映射到外部世界。所以,docker-compose的相关部分看起来像这样:

api:
  image: tomcat:8.0-jre8
  container_name: api
  volumes:
    - ./deployment/api:/usr/local/tomcat/webapps
  external_links:
    - mysql:mysql
  ports:
    - "8080:8080"

根据日志,应用程序已成功部署,甚至liquibase迁移正在应用:

21-Nov-2016 07:11:03.671 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive /usr/local/tomcat/webapps/priz-0.5.war
21-Nov-2016 07:12:12.496 INFO [localhost-startStop-1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
2016-11-21T07:13:38.397268676Z 
Configuring Spring Security Core ...
... finished configuring Spring Security Core
2016-11-21T07:13:40.215275700Z 
2016-11-21T07:13:40.777432843Z 
Configuring Spring Security REST 2.0.0.M2...
... finished configuring Spring Security REST
2016-11-21T07:13:41.515464956Z 
INFO 11/21/16 7:14 AM: liquibase: Successfully acquired change log lock
INFO 11/21/16 7:14 AM: liquibase: Reading from priz.DATABASECHANGELOG
INFO 11/21/16 7:14 AM: liquibase: Successfully released change log lock
21-Nov-2016 07:15:09.019 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive /usr/local/tomcat/webapps/priz-0.5.war has finished in 245,345 ms
21-Nov-2016 07:15:09.026 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-apr-8080"]
21-Nov-2016 07:15:09.036 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-apr-8009"]
21-Nov-2016 07:15:09.038 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 245425 ms

但是,当我尝试访问任何一个现有端点时,我得到了404。

现在,同样基于日志,请求实际上是在命中服务器:

==> ./logs/localhost_access_log.2016-11-21.txt <==
172.17.0.1 - - [21/Nov/2016:07:15:09 +0000] "GET / HTTP/1.1" 404 -
172.17.0.1 - - [21/Nov/2016:07:15:09 +0000] "GET / HTTP/1.1" 404 -
172.17.0.1 - - [21/Nov/2016:07:16:45 +0000] "GET / HTTP/1.1" 404 -
172.17.0.1 - - [21/Nov/2016:07:17:01 +0000] "GET / HTTP/1.1" 404 -
172.17.0.1 - - [21/Nov/2016:07:17:07 +0000] "GET /index HTTP/1.1" 404 -
172.17.0.1 - - [21/Nov/2016:07:28:24 +0000] "GET /api/user/register HTTP/1.1" 404 -
172.17.0.1 - - [21/Nov/2016:07:28:46 +0000] "POST /api/user/register HTTP/1.1" 404 -

我如何解决这个问题怎么调试呢?我错过了什么? 日志中没有什么特别之处。

此外,我尝试了不同版本的tomcat,包括在AWS EBS上运行的完整版本。 此外,尝试通过nginx代理请求,结果相同。

1 个答案:

答案 0 :(得分:3)

你的战争文件名是priz-0.5.war。因此上下文名称也是priz-0.5。 你必须打电话给例如http://localhost:8080/priz-0.5

如果您想将其称为http://localhost:8080/,只需将war-File重命名为ROOT.war