无法访问部署在Docker容器中的Webapp

时间:2018-10-16 11:18:14

标签: docker glassfish-4

我目前正在使用Docker(或尝试使用Docker),所以我设置了一个webapp。 我使用Eclipse创建了一个maven项目,构建了一个.war文件,并将其部署在Glassfish服务器上(以检查其是否有效)。 这行得通,我可以通过

访问webapp
localhost:8080/myApp

现在我创建了一个Dockerfile,从中创建了一个Docker映像,并通过

docker run -d -p 8080:8080 myApp

这也有效,并且

docker ps -a

显示容器正在运行。 但是,当我尝试立即访问localhost:8080 / myApp时,我得到

  

ERR_CONNECTION_REFUSED

我用Chrome,Firefox和Internet Explorer尝试过。

docker exec -it <myContainer> bash

为我在容器内提供了一个外壳(如预期)。当我这样做

curl -v localhost:8080/myApp

在这里,我得到了期望的输出(来自myApp的页面)。

所以对我来说,这意味着容器正在运行,glassfish服务器正在容器内部运行,并且myApp已“正确”部署到了该服务器,但仍然无法从容器外部访问myApp。

docker ps -a

顺便说一句,

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                                                                       NAMES
9514b1ab6dd0        myApp              "sh /start.sh"      9 minutes ago       Up 9 minutes        4848/tcp, 8181/tcp, 0.0.0.0:8080->8080/tcp   admiring_cori

Dockerfile当然包含该行

EXPOSE 8080

任何想法在这里可能出什么问题吗?

编辑:

这些是Dockerfile的内容:

FROM glassfish:4.0

COPY myApp.war /
COPY start.sh /


EXPOSE 8080

RUN ["chmod", "+x", "/start.sh"]

ENTRYPOINT ["sh", "/start.sh"]

start.sh:

#!/bin/sh

/usr/local/glassfish4/bin/asadmin start-domain
/usr/local/glassfish4/bin/asadmin -u admin deploy /myApp.war
/usr/local/glassfish4/bin/asadmin stop-domain
/usr/local/glassfish4/bin/asadmin start-domain --verbose

编辑2:

docker logs <container>

收益

Waiting for domain1 to start ...............
Successfully started the domain : domain1
domain  Location: /usr/local/glassfish4/glassfish/domains/domain1
Log File: /usr/local/glassfish4/glassfish/domains/domain1/logs/server.log
Admin Port: 4848
Command start-domain executed successfully.
Application deployed with name myApp.
Command deploy executed successfully.
Waiting for the domain to stop .
Command stop-domain executed successfully.
Launching GlassFish on Felix platform
Registered com.sun.enterprise.glassfish.bootstrap.osgi.EmbeddedOSGiGlassFishRuntime@2ba2f40 in service registry.
Registry Info:: Total repositories: 1, Total modules = 293
Attached repository: []

[... Registered Modules... all with State = [NEW] or [RESOLVED]]

Found populator: com.sun.enterprise.v3.server.GFDomainXml

#!## LogManagerService.postConstruct : rootFolder=/usr/local/glassfish4/glassfish
#!## LogManagerService.postConstruct : templateDir=/usr/local/glassfish4/glassfish/lib/templates
#!## LogManagerService.postConstruct : src=/usr/local/glassfish4/glassfish/lib/templates/logging.properties
#!## LogManagerService.postConstruct : dest=/usr/local/glassfish4/glassfish/domains/domain1/config/logging.properties

0 个答案:

没有答案