无法从外部访问在端口4567上的Docker容器中运行的应用 [英] App running in Docker container on port 4567 can't be accessed from the outside

查看:194
本文介绍了无法从外部访问在端口4567上的Docker容器中运行的应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用重新创建设置所需的所有文件更新帖子。 –仍然是同样的问题。无法访问在容器中运行的服务。

Updating the post with all files required to recreate the setup. – Still the same problem. Not able to access service running in container.

FROM python:3

RUN apt-get update
RUN apt-get install -y ruby rubygems
RUN gem install sinatra

WORKDIR /app
ADD . /app/

EXPOSE 4567
CMD ruby hei.rb -p 4567

hei.rb

require 'sinatra'

get '/' do
  'Hello world!'
end

docker-compose.yml

version: '2'

services:
  web:
    build: .
    ports:
      - "4567:4567"

我正在启动通过运行 docker-compose up --build参加聚会。

docker ps 返回:
0.0.0.0:4567->4567/tcp

I'm starting the party by running docker-compose up --build . docker ps returns: 0.0.0.0:4567->4567/tcp

仍然,端口4567没有响应。使用主机的curl测试。

$ curl 127.0.0.1:4567 # and 0.0.0.0:4567

localhost:4567在容器中的答复

$ docker-compose exec web curl localhost:4567
Hello world!%`

我该怎么办能够访问在端口4567上运行的Sinatra应用程序?

What should I do to be able to access the Sinatra app running on port 4567?

推荐答案

Sinatra绑定了错误的接口。
通过添加 -o 开关进行固定。

Sinatra was binding to the wrong interface. Fixed by adding the -o switch.

CMD红宝石黑。 rb -p 4567 -o 0.0.0.0

这篇关于无法从外部访问在端口4567上的Docker容器中运行的应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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