1

I have built a Docker image with Ruby and some gems as a starting point for my projects. Its available at: jikkujose/trial. I am trying this out in a Mac, using the default docker-toolbox.

I am trying to use it to host a single file app. I am launching it as follows:

docker run -itdP -v .:/app jikkujose/docker

The current directory contains a file app.rb with the following:

require 'sinatra'

class App < Sinatra::Base
  set :bind, "0.0.0.0"

  get '/' do
    'This is interesting :)'
  end
end

App.run!

I am able to attach to the container to launch the app. And the following is seen when I do: docker ps -a

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                        PORTS                     NAMES
92498cafd985        jikkujose/trial     "/bin/bash"              18 seconds ago      Up 18 seconds                 0.0.0.0:32780->4567/tcp   boring_meitner

And I am trying to access the application using the ip obtained via docker-machine ip default.

While trying to access the the app using curl, I am getting the following:

curl: (7) Failed to connect to 192.168.99.100 port 32780: Connection refused
Jikku Jose
  • 18,306
  • 11
  • 41
  • 61

1 Answers1

0
Failed to connect to 192.168.99.100 port 32780: Connection refused

That should mean there is no listener, or, since a docker exec <container id> curl http://localhost:4567 does work, that the listener does not accept queries from broadcast, only from localhost...

Your entrypoint and cmd are:

ENTRYPOINT ["/opt/rubies/ruby-2.2.2/bin/ruby"]
CMD ["/app/app.rb"]

Check if others mean to launch a sinatra app would work better with a docker environment: for instance "Dockerizing simple Sinatra app using docker and fig" (fig is the old name of docker compose)

Before that, check if the mapped port is forwarded at the VirtualBox level:

VBoxManage controlvm boot2docker-vm natpf1 "name,tcp,127.0.0.1,32780,,32780"
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I have already done that; I am doing a `curl` on the exposed port itself and also accessing using the `IP` of the `VM`. – Jikku Jose Oct 16 '15 at 13:25
  • @JikkuJose my point is, when you use -P , you don't know which port is actually used: what a docker ps -a returns? – VonC Oct 16 '15 at 13:48
  • I know that, I have already provided the output of `docker ps -a` and I am using the randomly chosen port: `32780 `. (You can scroll that output included with the question to see it) – Jikku Jose Oct 16 '15 at 13:59
  • @JikkuJose Right. I have rewritten the answer to propose an alternative – VonC Oct 16 '15 at 19:23
  • I didn't build it using a `Dockerfile`. Thanks for the link, I had reviewed it earlier. My goal isn't running Sinatra; its just to access an exposed port and running a server in the container launched via command line than the `Dockerfile`. – Jikku Jose Oct 17 '15 at 04:54
  • @JikkuJose I understand, could it be that the mapped port is not declared in the VirtualBox network setting? I have edited the answer for more (with a link to http://stackoverflow.com/a/31509414/6309) – VonC Oct 17 '15 at 04:59
  • I am not using `boot2docker`; but the latest `docker-toolbox`. Also, the same ports work on another image that was downloaded. It seems to me that something subtle is missing in the way I run it. – Jikku Jose Oct 17 '15 at 06:46
  • @JikkuJose same issue: toolbox or boot2docker: you need to forward the port on the VM side. – VonC Oct 17 '15 at 06:59
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/92572/discussion-between-jikku-jose-and-vonc). – Jikku Jose Oct 17 '15 at 11:36
  • can you look at this question: http://stackoverflow.com/questions/33667467/cant-access-dockers-exposed-port-in-ubuntu – Jikku Jose Nov 13 '15 at 10:36