Docker容器中的Tomcat服务无法访问(错误404)

时间:2018-05-28 13:45:56

标签: docker tomcat http-status-code-404 http-proxy

我在基于CentOS 7映像的容器中使用Tomcat 7,但我无法访问任何部署的应用程序。即便如此:从容器运行curl -v 'http://localhost:8080'会返回错误:

* About to connect() to localhost port 8080 (#0)
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.29.0
> Host: localhost:8080
> Accept: */*
> 
< HTTP/1.1 404 Not Found
< Server: Apache-Coyote/1.1
< Content-Length: 0
< Date: Mon, 28 May 2018 13:14:41 GMT
< 
* Connection #0 to host localhost left intact

用容器的IP地址localhost替换172.17.0.2会产生同样的错误。

我使用docker run选项-p 28080:8080将容器的8080端口绑定到主机的28080端口,但我也无法从主机访问该服务。但是我尝试在容器中使用nginx并且它工作得很好(我可以从主机和容器访问它)所以我认为它是Tomcat问题而不是Docker。

此外,我运行了nmap,结果如下:

[root@a115404a7a03 /]# nmap -sT -O localhost

Starting Nmap 6.40 ( http://nmap.org ) at 2018-05-28 13:23 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000070s latency).
Other addresses for localhost (not scanned): 127.0.0.1
Not shown: 993 closed ports
PORT     STATE SERVICE
5432/tcp open  postgresql
7001/tcp open  afs3-callback
7002/tcp open  afs3-prserver
7004/tcp open  afs3-kaserver
7007/tcp open  afs3-bos
8009/tcp open  ajp13
8080/tcp open  http-proxy

我觉得奇怪的是,端口8080的服务是http-proxy,而不仅仅是http。我没有在Tomcat配置文件中找到任何代理设置,并且未设置环境变量http_proxy

我在Dockerfile中启用Tomcat服务,如下所示:RUN systemctl enable tomcat.service

我想也许这可能与我使用代理环境变量集(使用--build-arg)构建映像的事实有关但我从Dockerfile中删除了上面的行并在容器启动后手动启动它跑步,但没有用。

最后一点,我在Tomcat中部署的一个应用程序在部署后运行测试请求,我可以在日志中看到它正在运行,它获得了代码200:

127.0.0.1 - - [28/May/2018:13:03:00 +0000] "GET /rasdaman/ows?service=WCS&version=2.0.1&request=GetCapabilities HTTP/1.1" 200 9420

如果我运行curl -v 'http://localhost:8080/rasdaman/ows?service=WCS&version=2.0.1&request=GetCapabilities但是我收到错误404。

知道发生了什么事吗?

由于

修改

我尝试使用nmap选项运行-sV,这就是我所得到的:

[root@a115404a7a03 /]# nmap -sV -O localhost

Starting Nmap 6.40 ( http://nmap.org ) at 2018-05-28 14:05 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000060s latency).
Other addresses for localhost (not scanned): 127.0.0.1
Not shown: 993 closed ports
PORT     STATE SERVICE        VERSION
5432/tcp open  postgresql     PostgreSQL DB
7001/tcp open  afs3-callback?
7002/tcp open  afs3-prserver?
7004/tcp open  afs3-kaserver?
7007/tcp open  afs3-bos?
8009/tcp open  ajp13          Apache Jserv (Protocol v1.3)
8080/tcp open  http           Apache Tomcat/Coyote JSP engine 1.1

它显示http而非http-proxy

编辑2

下面是Dockerfile:

FROM centos:7

# Install prerequisites
RUN yum clean all
RUN yum -q -y update
RUN yum -q -y install sudo curl wget less vim unzip
RUN yum -q -y install epel-release

RUN sed -i '/^Defaults.*requiretty$/d' /etc/sudoers

# Instructions at http://rasdaman.org/wiki/InstallFromRPM
RUN curl "http://download.rasdaman.org/packages/rpm/nightly/CentOS/7/x86_64/rasdaman.repo" -o /etc/yum.repos.d/rasdaman.repo
RUN yum clean all
RUN yum -q -y update && yum -y install rasdaman
RUN test -f /etc/profile.d/rasdaman.sh && source /etc/profile.d/rasdaman.sh

# Install python dependencies
RUN pip install glob2

# Enable on startup
RUN systemctl enable postgresql.service
RUN systemctl enable tomcat.service   ## I tried with this line commented or not, see above.
RUN systemctl enable rasdaman.service

RUN /etc/init.d/rasdaman start

# Tomcat (localhost:8080/rasdaman/ows)
EXPOSE 8080

RUN yum -q -y install nmap

CMD ["/usr/sbin/init"]

编辑3

这是Tomcat日志的摘录:

May 30, 2018 8:25:09 AM org.apache.catalina.startup.HostConfig deployWARs
SEVERE: Error waiting for multi-thread deployment of WAR files to complete
java.lang.InterruptedException
    at java.util.concurrent.FutureTask.awaitDone(FutureTask.java:404)
    at java.util.concurrent.FutureTask.get(FutureTask.java:191)
    at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:832)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:495)
    at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1757)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:333)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
    at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1370)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1542)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1552)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1520)
    at java.lang.Thread.run(Thread.java:748)

May 30, 2018 8:25:11 AM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deployment of web application archive /var/lib/tomcat/webapps/rasdaman.war has finished in 35,256 ms

0 个答案:

没有答案