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 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. 

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

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

@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.