0

I'm currently getting into Docker (or trying to), so I set up a little webapp. I used Eclipse to create a maven-Project, built a .war-file and deployed it (to check if it works) locally on a Glassfish server. This worked, and I could access the webapp via

localhost:8080/myApp

Now I created a Dockerfile, built a docker image from that and ran the whole thing via

docker run -d -p 8080:8080 myApp

This also works, and

docker ps -a

shows that a container is running. However, when I try to access localhost:8080/myApp now, I get

ERR_CONNECTION_REFUSED

I tried this with Chrome, Firefox and Internet Explorer.

docker exec -it <myContainer> bash

gives me a shell inside the container (as expected). When I do

curl -v localhost:8080/myApp

here, I get the output I expect (the page from myApp).

So for me, this means that the container is running, the glassfish server is running inside the container, and myApp has been deployed "properly" to said server, yet still I cannot access myApp from outside the container.

docker ps -a

yields this, btw:

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

The Dockerfile does of course contain the line

EXPOSE 8080

Any ideas what might be wrong here?

Edit:

These are the contents of the 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

Edit 2:

docker logs <container>

yields

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
Flo
  • 223
  • 3
  • 14
  • 1
    Please, post your DockerFile so we can see how you started your container – Guilherme Uzeda Oct 16 '18 at 11:40
  • @GuilhermeUzeda: I edited the question to include the dockerfile – Flo Oct 16 '18 at 11:43
  • Did you check the container's log? You can do that with: `docker logs container_id` – Guilherme Uzeda Oct 16 '18 at 11:50
  • @GuilhermeUzeda I edited again with the log content. I don't see anything fishy (huehue) there. – Flo Oct 16 '18 at 11:58
  • You can remove the `EXPOSE 8080` from the Dockerfile, it's just a documentation line. Under which OS are you running this container? It looks more like a configuration issue on the application's side. Since you get the `ERR_CONNECTION_REFUSED` it means you **can** access the container, but it refuses to talk to you. – Mike Doe Oct 16 '18 at 11:58
  • Do you have access to "http://localhost:8080/" ? – Sarath Kumar Oct 16 '18 at 12:06
  • @emix I'm running the container under Windows 10. The thing is: When I deploy the same application (i.e. the same .war) locally to a glassfish server, it works just fine (no ERR_CONNECTION_REFUSED). – Flo Oct 16 '18 at 12:07
  • @SarathKumar Ah, actually, localhost:8080/ gives me the same error. I didn't have that issue when just deploying the .war directly to glassfish (without docker)... – Flo Oct 16 '18 at 12:09
  • The container configuration is fine. The webserver refuses to talk to you. It's a matter of proper configuration so it responds to non-local connections. It works when you deploy the app locally because only then your request origins from the same interface. – Mike Doe Oct 16 '18 at 12:29
  • @emix Just to make sure I understand correctly: I need to find a way to configure the glassfish server inside the docker container in such a way that it will talk to me when I access it from outside the container? – Flo Oct 16 '18 at 12:33
  • Looks like so exactly. Don't think about containers, your application is oblivous to the fact that it runs inside one. Think about interfaces and different networks. You can verify the container is responding by running the curl in verbose mode: `curl -I -v http://localhost` on your machine. You should always debug connections this way before asking in the first place. – Mike Doe Oct 16 '18 at 12:36
  • Anyway, are you [accessing your container properly](https://blogs.technet.microsoft.com/networking/2017/11/06/available-to-windows-10-insiders-today-access-to-published-container-ports-via-localhost127-0-0-1/)? – Mike Doe Oct 16 '18 at 12:43

0 Answers0