简体   繁体   English

在码头工人中运行轨道

[英]Running rails in docker

I'm learning docker and create a Dockerfile which is exactly 我正在学习docker并创建一个完全正确的Dockerfile

FROM ruby:2.6
RUN bundle config --global frozen 1

WORKDIR /usr/src/app

COPY Gemfile Gemfile.lock ./

RUN bundle install

COPY . .

EXPOSE 3000

CMD ["rails", "server", "-b", "0.0.0.0", "-p", "3000"]

but when I try curl 0.0.0.0:3000 or open it in a browser it says connection is refused. 但是当我尝试curl 0.0.0.0:3000或在浏览器中打开它时,它表示拒绝连接。 It should not related with the rails app I think because it's just a completely new app. 它应该与我认为的rails应用程序无关,因为它只是一个全新的应用程序。

after I input Ctrl-c then it show 输入Ctrl-c然后显示

=> Booting Puma
=> Rails 5.2.3 application starting in development 
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.12.1 (ruby 2.6.3-p62), codename: Llamas in Pajamas
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop
- Gracefully stopping, waiting for requests to finish
=== puma shutdown: 2019-05-05 04:00:42 +0000 ===
- Goodbye!
Exiting

I tried to attach shell into container and I saw puma with ps aux so what is wrong 我试图将shell连接到容器中,我看到了与ps aux puma,所以出了什么问题

It's important how you start your container. 如何启动容器非常重要。 By default you don't publish the port to the host machine so the opened port of your rails application is only accessible inside of your container. 默认情况下,您不会将端口发布到主机,因此只能在容器内部访问rails应用程序的打开端口。 If you want to publish the port run it like that: 如果要发布端口,请执行以下操作:

docker run -p 3000:3000 <image>

You can find more information in the documentation . 您可以在文档中找到更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM