我有一个Docker容器:(称为Dockerfile.web
,相关部分)
ARG PORT=3000
ENV PORT=$PORT
EXPOSE $PORT
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["rails", "server"]
彪马:config/puma.rb
before_fork do
ActiveRecord::Base.connection_pool.disconnect! if defined? ActiveRecord
end
on_worker_boot do
ActiveRecord::Base.establish_connection if defined? ActiveRecord
end
preload_app!
因此,当我先运行heroku container:push web
之后再运行heroku container:release web
时,应用程序将部署,但是b / c无法启动puma服务器,该端口无法连接:
Booting Puma
Rails 5.2.2 application starting in development
Run `rails server -h` for more startup options
Puma starting in cluster mode...
* Version 3.12.0 (ruby 2.6.0-p0), codename: Llamas in Pajamas
* Min threads: 5, max threads: 5
* Environment: development
* Process workers: 1
* Preloading application
* Listening on tcp://localhost:41626
Use Ctrl-C to stop
- Worker 0 (pid: 28) booted, phase: 0
Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
Stopping process with SIGKILL
我正在关注the official guide,但是我没有添加以下部分:
rackup DefaultRackup
port ENV['PORT'] || 3000
environment ENV['RACK_ENV'] || 'development'
我的错误在哪里?有什么想法吗?
答案 0 :(得分:0)
答案 1 :(得分:0)
对于到达这里的人们,解决方案是直接从docker CMD
调用puma服务器,以便应用配置文件中的所有设置。原因是在heroku上,端口之类的内容是动态添加的,因此容器映像(较早构建)不会包含那些映像。以某种方式在Dockerfile中使用$PORT
值也无济于事。解决方法是
CMD ["bundle", "exec", "puma", "-C", "config/puma.rb"]
# or if you prefer the bash style
CMD bundle exec puma -C config/puma.rb