0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Railsチュートリアル デプロイが上手くいかない

Last updated at Posted at 2025-01-13

デプロイ時に発生したエラーがとりあえず解決(これで良いのかは別として)したので、備忘録として記載。

1. 状況

Railsチュートリアルの10章あたりまでは、とりあえずデプロイできていたはずなのだが、11章終了後のデプロイでエラーが発生した。

log
Port scan timeout reached, no open ports detected. Bind your service to at least one port. If you don't need to receive traffic on any port, create a background worker instead.
Docs on specifying a port: https://render.com/docs/web-services#port-binding

2. 実施したこと

2.1. PORT番号の修正

エラーログに記載のURLを確認したところ、Renderのデフォルトのポートは10000であるとの記載があったので、PORT番号を10000に修正した。

config/puma.rb
- port ENV.fetch("PORT", 3000)
+ bind "tcp://0.0.0.0:#{ENV.fetch('PORT') { 10000 }}"
Dockerfile
- EXPOSE 80
+ EXPOSE 10000
.devcontainer/docker-compose.yml
services:
  app:
    ~略~
    environment:
      BINDING: 0.0.0.0
+      PORT: 10000             # Renderで期待されるポート
+      RAILS_ENV: production   # 本番環境の指定

また、dockerの環境変数としてPORT10000を設定した。

2.2. command: sleep infinityの削除

docker-compose.ymlで設定されているcommand: sleep infinityは、コンテナをただ待機させるだけらしい。puma.rbを読み込むように変更

.devcontainer/docker-compose.yml
services:
  app:
    ~略~
-    command: sleep infinity
+    command: bundle exec puma -C config/puma.rb

2.3. Railsサーバーの起動方法を修正

rails serverは、開発環境でのデフォルトのサーバーであるため、pumaによるサーバーの軌道に変更する。

Dockerfile
- CMD ["./bin/thrust", "./bin/rails", "server"]
+ CMD ["bundle", "exec", "puma", "-C", "config/puma.rb"]

解決

ここまでの修正でデプロイはできたが、上手く動いてはいない。色々修正は必要そう。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?