2

I’ve run a web service in a docker container on a custom port (8080). Here, I’m trying to run a container, exposing the relevant container’s port (as seen here), but the no avail.

docker run -p 127.0.0.1:8080:8080 beatthemarket run wait

But I can’t seem to reach that web service endpoint.

i) Am I correctly exposing the container's port? ii) How can troubleshoot if it's the port that's unavailable, or if my web service just isn't getting called (it would be nice to be able to shell into the container and just curl the endpoint).

My Dockerfile can be seen here. And I’m using Adzerk’s boot-clj base image.

Actually running docker, each time retrieves a bunch of jars. Then boot blocks (the wait task), which is what I want (a web server will be handling web requests). And this is where I’m lost. Boot, in docker, blocks as I’ve asked it to. But I can’t seem to get the basic Hello World message that a root URI should return.

$ docker run -p 127.0.0.1:8080:8080 beatthemarket run wait
Downloading https://github.com/boot-clj/boot/releases/download/2.5.5/boot.jar...
Retrieving dynapath-0.2.3.jar from https://clojars.org/repo/
Retrieving pod-2.5.5.jar from https://clojars.org/repo/
Retrieving shimdandy-impl-1.2.0.jar from https://repo1.maven.org/maven2/
Retrieving core-2.5.5.jar from https://clojars.org/repo/
...
Implicit target dir is deprecated, please use the target task instead.
Set BOOT_EMIT_TARGET=no to disable implicit target dir.

The Chrome, curl and wget all say that the connection is refused.

$ curl http://127.0.0.1:8080/
curl: (7) Failed to connect to 127.0.0.1 port 8080: Connection refused

$ wget http://127.0.0.1:8080/
--2016-04-21 20:07:32--  http://127.0.0.1:8080/
Connecting to 127.0.0.1:8080... failed: Connection refused. 
8
  • You forgot to say what happens when you try to connect to the service. Apr 21, 2016 at 23:31
  • Can you post the output of a netstat -tunlp?
    – prateek61
    Apr 22, 2016 at 2:35
  • @MichaelHampton Absolutely. I've added docker output, and that nothing happens when trying to connect to the web service.
    – Frye
    Apr 22, 2016 at 3:05
  • @prateek61, I'm on OSX, and when I run netstat -tunlp, it tells me netstat: option requires an argument -- p.
    – Frye
    Apr 22, 2016 at 3:11
  • Sorry, just do netstat -tunl for OSX
    – prateek61
    Apr 22, 2016 at 3:12

2 Answers 2

4

You need to add the EXPOSE statement to your Dockerfile for port 8080.

Here's the reference from Docker: https://docs.docker.com/engine/reference/builder/#expose

Your final Dockerfile should look like this:

FROM adzerk/boot-clj

EXPOSE 8080

WORKDIR /app
COPY . /app
4
  • After rebuilding the image, docker run -p 127.0.0.1:8080:8080 beatthemarket run wait still refuses a connection. According to the docs, running docker run -P beatthemarket run wait should Publish all exposed ports to the host interfaces. But the connection also gets refused there as well... How do I shell into the container to sanity check that the web service started?
    – Frye
    Apr 22, 2016 at 3:24
  • Update: I was able to shell into the container. And indeed the web server is up and responding to requests. So the issue is just that I can't access the container over HTTP. Dockerfile is here. And I'm failing with both docker run -p 127.0.0.1:8080:8080 beatthemarket run wait and docker run -P beatthemarket run wait commands.
    – Frye
    Apr 22, 2016 at 3:41
  • Try dropping the IP from the -p argument. Just use -p 8080:8080
    – Joe Doyle
    Apr 22, 2016 at 19:03
  • Indeed. That solved my problem. Can now access the web service in the docker container.
    – Frye
    Apr 23, 2016 at 6:58
0

the -p switch will punch a hole through your host bridging to your docker instance, -p host_port:docker_instance_port

Now you have to find out where does your docker host reside. If you are using VirtualBox, try to run :

docker-machine env

http://javagoogleappspot.blogspot.com/2018/07/docker-basics.html

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .