我确定我做了一些简单的错误,但是我无法在我的Mac上使用docker来正确地暴露端口。这就是我正在做的事情:
主持人从头开始:
> rails -v
Rails 5.0.0.1
> rails new dt6
# ... rails creates a new app
> cd dt6
然后我在rails app的根目录下添加这个Dockerfile:
FROM ruby:2.3.1
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
RUN mkdir /myapp
WORKDIR /myapp
ADD Gemfile /myapp/Gemfile
ADD Gemfile.lock /myapp/Gemfile.lock
RUN bundle install
ADD . /myapp
EXPOSE 3000
然后我构建图像并运行容器
> docker build -t dt6 .
> docker run --rm -p 3000:3000 dt6 rails s
=> Booting Puma
=> Rails 5.0.0.1 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.6.0 (ruby 2.3.1-p112), codename: Sleepy Sunday Serenity
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://localhost:3000
Use Ctrl-C to stop
看起来像普通的导轨/美洲狮“我准备开始提供”消息了。但是,从主机,我无法访问rails服务器:
> curl localhost:3000
curl: (52) Empty reply from server
我知道docker正在使用端口3000执行某事,因为我为随机端口收到了不同的消息:
> curl localhost:3001
curl: (7) Failed to connect to localhost port 3001: Connection refused
值得注意的是,rails服务器正在运行。如果我连接到容器并从内部击中rails服务器,它可以工作:
> docker exec -it dt6_container bash
root@6af33aa9c43b:/myapp# curl localhost:3000
<!DOCTYPE html>
<html>
<head>
#... a normal html response from the rails server
TLDR:在docker容器中运行rails服务器,当我从主机访问服务器时,我得到一个空响应。如果我希望能够从外部向此容器内部运行的rails服务器发出http请求,那么我做错了什么?
答案 0 :(得分:0)
尝试在CMD ["rails", "server", "-b", "0.0.0.0"]
之后将EXPOSE 3000
添加到您的泊坞窗文件中。