2

I've created a Dockerfile which looks like this:

FROM openjdk:8-jdk

COPY . .
ENTRYPOINT ["/bin/graphdb"]

EXPOSE 7200

On doing docker run 34a1650b461d -p 127.0.0.1:7200:7200 I see my service running as shown in the terminal output - however when I go to localhost:7200 I keep seeing This site can’t be reached 127.0.0.1 refused to connect.

Could anyone explain what I'm missing?

Also fyi - when I do docker ps, under PORTS I see 7200/tcp.

I read this page and followed what was described but to no luck.

Any help appreciated.

Thanks.

userMod2
  • 8,312
  • 13
  • 63
  • 115

1 Answers1

5

For docker run the order of the parameters matter, so this:

docker run 34a1650b461d -p 7200:7200

Is not the same as:

docker run -p 7200:7200 34a1650b461d

In the first case you are passing the parameters -p 7200:7200 to your ENTRYPOINT command /bin/graphdb; whereas in the second case, you are passing -p 7200:7200 to docker run, which is what you wanted.

How to validate when ports are correctly forwarded?

You can validate this by running docker ps and checking the PORTS column:

$ docker run -d 34a1650b461d -p 7200:7200
$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
03abc0b390ef        mytest              "/bin/graphdb -p 720…"   6 seconds ago       Up 5 seconds        7200/tcp            elegant_wescoff

Do you see how the COMMAND includes your -p? That's not what you wanted. So docker run was not interpreting that parameter at all. Also, you can see the PORTS column, which shows the port is exposed but not forwarded.

Whereas doing it like this:

$ docker run -d -p 7200:7200 34a1650b461d
$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                             NAMES
03abc0b390ef        mytest              "/bin/graphdb"           6 seconds ago       Up 5 seconds        0.0.0.0:7200->7200/tcp            elegant_wescoff

You can see now that -p is not being passed to COMMAND and that the port is forwarded: 0.0.0.0:7200->7200/tcp.

Daniel
  • 21,933
  • 14
  • 72
  • 101