Can't access the dockerized app launched from

2020-03-30 08:47发布

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

标签: ruby docker
1条回答
趁早两清
2楼-- · 2020-03-30 09:34
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"
查看更多
登录 后发表回答