Howto expose port in docker container

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 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 beatthemarket run wait
Retrieving dynapath-0.2.3.jar from
Retrieving pod-2.5.5.jar from
Retrieving shimdandy-impl-1.2.0.jar from
Retrieving core-2.5.5.jar from
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
curl: (7) Failed to connect to port 8080: Connection refused

$ wget
--2016-04-21 20:07:32--
Connecting to failed: Connection refused. 

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

Here's the reference from Docker:

Your final Dockerfile should look like this:

FROM adzerk/boot-clj


COPY . /app

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

@pratheek61 No result. netstat -tunl | grep 8080 returns empty.

You forgot to say what happens when you try to connect to the service.

Can you post the output of a netstat -tunlp?

@MichaelHampton Absolutely. I’ve added docker output, and that nothing happens when trying to connect to the web service.

@prateek61, I’m on OSX, and when I run netstat -tunlp, it tells me netstat: option requires an argument – p.

Sorry, just do netstat -tunl for OSX

@prateek61 netstat -tunl | wc has over 500 lines. It takes too long to copy the entire thing. But the output looks like this.

@Frye do you see 8080 listed in the output? Try grepping for it.