App running in Docker container on port 4567 can't be accessed from the outside

一曲冷凌霜 提交于 2019-12-25 08:18:57

问题


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"

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

Still, no respons from port 4567. Testing with curl from the host machine.

$ curl 127.0.0.1:4567 # and 0.0.0.0:4567

localhost:4567 replies within the containter

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

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


回答1:


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

CMD ruby hei.rb -p 4567 -o 0.0.0.0



来源:https://stackoverflow.com/questions/41614652/app-running-in-docker-container-on-port-4567-cant-be-accessed-from-the-outside

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!