无法从外部访问从命令行启动的dockerized应用程序 [英] Can't access the dockerized app launched from the command line from outside

查看:139
本文介绍了无法从外部访问从命令行启动的dockerized应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经建立了一个Docker的图像,Ruby和一些宝石作为我的项目的起点。可用: jikkujose / trial 。我正在Mac中尝试使用默认的docker-toolbox。



我正在尝试使用它来托管一个文件应用程序。我启动它如下:



docker run -itdP -v。:/ app jikkujose / docker p>

当前目录包含一个文件 app.rb ,其中包含以下内容:

  require'sinatra'

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

get'/'do
'这是有趣的:)'
end
结束

App.run!

我可以将附加到容器来启动应用程序。当我这样做时,看到以下内容: docker ps -a

  CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 
92498cafd985 jikkujose / trial/ bin / bash18秒前上18秒0.0.0.0:32780->4567/tcp boring_meitner

我正在尝试使用通过 docker-machine ip default获得的ip来访问应用程序>



在尝试使用 curl 访问该应用程序时,我得到以下内容:

  curl:(7)无法连接到192.168.99.100端口32780:连接拒绝


解决方案

 无法连接到192.168.99.100端口32780:连接拒绝

这应该意味着没有监听器,或者,因为 docker exec < container id> curl http:// localhost:4567 的工作,听众不接受来自广播的查询,只能从本地主机...



您的 entrypoint和cmd are

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

检查其他人是否想启动一个sinatra应用程序将会更好地使用docker环境:例如 使用docker和fig (fig是docker撰写的旧名称)



在此之前,检查映射端口是否为在VirtualBox级别转发

  VBoxManage controlvm boot2docker-vm natpf1name,tcp ,127。 0.0.1,32780,,32780


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

解决方案

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"

这篇关于无法从外部访问从命令行启动的dockerized应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆