我有一个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
时,应用程序会部署,但puma服务器无法启动b/c端口无法连接:
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'
我的错误可能出在哪里?有什么想法吗?
发布于 2019-03-20 14:37:02
发布于 2019-03-22 10:14:03
对于到达这里的人,解决方案是直接从docker CMD
调用puma服务器,以便应用配置文件中的所有设置。原因是在heroku上,像port这样的东西是动态添加的,所以容器镜像(之前构建的)将不会有这些镜像。不知何故,在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
https://stackoverflow.com/questions/55262369
复制相似问题