Home > Software engineering >  Unable to access published ports in Docker from local machine
Unable to access published ports in Docker from local machine

Time:10-27

I want to dockerize an older jboss server (7.0.0). This is my Dockerfile and docker-compose.yml:

FROM centos:7.9.2009

RUN yum -y install java-1.8.0-openjdk-devel unzip

COPY jboss-eap-7.0.0.zip .

RUN unzip jboss-eap-7.0.0.zip -d /opt/
RUN ln -s /opt/jboss-eap-7.0/ /opt/jboss
RUN adduser jboss
RUN chown -R jboss /opt/jboss-eap-7.0/ /opt/jboss

ENTRYPOINT [ "/opt/jboss/bin/standalone.sh -Djboss.bind.address=0.0.0.0 -Djboss.bind.address.management=0.0.0.0" ]
version: '3.0'

services:
  ab3:
    build: .
    ports:
      - "8080:8080"
      - "9990:9990"

In the logs I can see that jboss has started successfully and is listening on ports:

INFO  [org.wildfly.extension.undertow] (MSC service thread 1-5) WFLYUT0006: Undertow HTTP listener default listening on 127.0.0.1:8080
...
INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0060: Http management interface listening on http://127.0.0.1:9990/management
INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0051: Admin console listening on http://127.0.0.1:9990

When checking in the browser with http://localhost:8080/ I get an ERR_EMPTY_RESPONSE. What did I miss here?

CodePudding user response:

Your need to check why your app is not binding to 0.0.0.0, it will only accept connection within the container when binded to 127.0.0.1:

...Undertow HTTP listener default listening on 127.0.0.1:8080 ...listening on http://127.0.0.1:9990/management ...listening on http://127.0.0.1:9990

CodePudding user response:

There are two forms of the Dockerfile ENTRYPOINT and CMD instructions (and also RUN). If you specify a JSON array, you must split it into words yourself; each item in the array is essentially processed as a quoted shell word. It may be easier to specify a bare command without the JSON syntax, in which case Docker will launch a shell to process the command line for you.

Since the form you have in the question has a single JSON word, Docker will try to interpret that whole word as the command to run, including the spaces and hyphens as part of the filename and with no options. I would expect the container to not start up at all, giving a "no such file or directory" error. You need to either break the command up into separate words manually or use the shell form:

# Shell form
ENTRYPOINT /opt/jboss/bin/standalone.sh -Djboss.bind.address=0.0.0.0 -Djboss.bind.address.management=0.0.0.0
# JSON-array form
ENTRYPOINT ["/opt/jboss/bin/standalone.sh", "-Djboss.bind.address=0.0.0.0", "-Djboss.bind.address.management=0.0.0.0"]

If you use the JSON-array form, you can specify additional options after the image name in a docker run option, or as a Compose command:. If you use the shell form the command part is completely ignored.

(There is a style choice as to whether to make this the container ENTRYPOINT or CMD. I tend to prefer CMD since it is easier to do things like launch debugging shells on an image, and because there is a common pattern of using ENTRYPOINT as a wrapper to do some first-time setup and then run the CMD. I suggested changing to CMD in a comment, but it's not essential to this answer.)

  • Related