ECSでrailsのコンテナを動かしたい
開いていただきありがとうございます。
プログラミング初学者です。
ECSでrailsのコンテナを動かしたところ、一瞬起動しその後エラーにて停止してしまいます。
エラーメッセージを確認したところデータベース周りでエラーが出て落ちているようですが、
知識が浅すぎて、具体的にどのあたりを確認すれば良いのか検討がついていない状態です。
この問題を解決する方法、または必要な経験や知識、どの辺を確認したら〜などがありましたら
ご教示願いたいです。
(AWSは通勤中に動画で見ている程度の知識となります、、)
なお、情報が足りない等ございましたら遠慮なく叱っていただければと思います。
※作成は下記記事を参考にしておりました。
https://qiita.com/Shogo1222/items/dcbc1e50f6fc83f48b44
発生している問題・エラーメッセージ
=> Booting Puma => Rails 6.1.4 application starting in development => Run `bin/rails server --help` for more startup options Puma starting in single mode... * Puma version: 5.3.2 (ruby 2.6.3-p62) ("Sweetnighter") * Min threads: 5 * Max threads: 5 * Environment: development * PID: 1 * Listening on http://0.0.0.0:3000 Use Ctrl-C to stop 2021-07-20 08:16:58 +0900 Rack app ("GET /" - (10.20.4.88)): #<NoMethodError: Cannot load database configuration: undefined method `[]' for nil:NilClass> 2021-07-20 08:16:58 +0900 Rack app ("GET /" - (10.20.3.219)): #<NoMethodError: Cannot load database configuration: undefined method `[]' for nil:NilClass> Started GET "/" for 10.20.4.88 at 2021-07-20 08:17:25 +0900 ActiveRecord::ConnectionNotEstablished (No connection pool for 'ActiveRecord::Base' found.): activerecord (6.1.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:1125:in `retrieve_connection' activerecord (6.1.4) lib/active_record/connection_handling.rb:327:in `retrieve_connection' activerecord (6.1.4) lib/active_record/connection_handling.rb:283:in `connection' activerecord (6.1.4) lib/active_record/migration.rb:611:in `connection' activerecord (6.1.4) lib/active_record/migration.rb:606:in `build_watcher' activerecord (6.1.4) lib/active_record/migration.rb:588:in `block in call' activerecord (6.1.4) lib/active_record/migration.rb:587:in `synchronize' activerecord (6.1.4) lib/active_record/migration.rb:587:in `call' actionpack (6.1.4) lib/action_dispatch/middleware/callbacks.rb:27:in `block in call' activesupport (6.1.4) lib/active_support/callbacks.rb:98:in `run_callbacks' actionpack (6.1.4) lib/action_dispatch/middleware/callbacks.rb:26:in `call' actionpack (6.1.4) lib/action_dispatch/middleware/executor.rb:14:in `call' actionpack (6.1.4) lib/action_dispatch/middleware/actionable_exceptions.rb:18:in `call' actionpack (6.1.4) lib/action_dispatch/middleware/debug_exceptions.rb:29:in `call' actionpack (6.1.4) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call' railties (6.1.4) lib/rails/rack/logger.rb:37:in `call_app' railties (6.1.4) lib/rails/rack/logger.rb:26:in `block in call' activesupport (6.1.4) lib/active_support/tagged_logging.rb:99:in `block in tagged' activesupport (6.1.4) lib/active_support/tagged_logging.rb:37:in `tagged' activesupport (6.1.4) lib/active_support/tagged_logging.rb:99:in `tagged' railties (6.1.4) lib/rails/rack/logger.rb:26:in `call' actionpack (6.1.4) lib/action_dispatch/middleware/remote_ip.rb:81:in `call' actionpack (6.1.4) lib/action_dispatch/middleware/request_id.rb:26:in `call' rack (2.2.3) lib/rack/runtime.rb:22:in `call' activesupport (6.1.4) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call' actionpack (6.1.4) lib/action_dispatch/middleware/executor.rb:14:in `call' actionpack (6.1.4) lib/action_dispatch/middleware/static.rb:24:in `call' rack (2.2.3) lib/rack/sendfile.rb:110:in `call' actionpack (6.1.4) lib/action_dispatch/middleware/host_authorization.rb:98:in `call' rack-cors (1.1.1) lib/rack/cors.rb:100:in `call' railties (6.1.4) lib/rails/engine.rb:539:in `call' puma (5.3.2) lib/puma/configuration.rb:249:in `call' puma (5.3.2) lib/puma/request.rb:77:in `block in handle_request' puma (5.3.2) lib/puma/thread_pool.rb:338:in `with_force_shutdown' puma (5.3.2) lib/puma/request.rb:76:in `handle_request' puma (5.3.2) lib/puma/server.rb:438:in `process_client' puma (5.3.2) lib/puma/thread_pool.rb:145:in `block in spawn_thread' Started GET "/" for 10.20.3.219 at 2021-07-20 08:17:25 +0900
該当のソースコード
database.yml
default: &default adapter: mysql2 encoding: utf8mb4 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> username: <%= ENV.fetch('MYSQL_USER') { 'root' } %> password: <%= ENV.fetch('MYSQL_PASSWORD') { 'password' } %> host: db development: <<: *default database: app_development test: <<: *default database: app_test username: username password: password production: <<: *default host: <%= Rails.application.credentials.rds[:host] %> database: <%= Rails.application.credentials.rds[:database] %> username: <%= Rails.application.credentials.rds[:username] %> password: <%= Rails.application.credentials.rds[:password] %>
Dockerfile
# イメージの指定 FROM ruby:2.6.3-alpine3.10 # 必要パッケージのダウンロード ENV RUNTIME_PACKAGES="linux-headers libxml2-dev make gcc libc-dev nodejs tzdata mysql-dev mysql-client yarn" \ DEV_PACKAGES="build-base curl-dev" \ HOME="/app" \ LANG=C.UTF-8 \ TZ=Asia/Tokyo # 作業ディレクトリに移動 WORKDIR ${HOME} # ホスト(自分のパソコンにあるファイル)から必要ファイルをDocker上にコピー ADD Gemfile ${HOME}/Gemfile ADD Gemfile.lock ${HOME}/Gemfile.lock RUN apk update RUN apk upgrade RUN apk add --update --no-cache ${RUNTIME_PACKAGES} RUN apk add --update --virtual build-dependencies --no-cache ${DEV_PACKAGES} RUN bundle install -j4 RUN apk del build-dependencies RUN rm -rf /usr/local/bundle/cache/* \ /usr/local/share/.cache/* \ /var/cache/* \ /tmp/* \ /usr/lib/mysqld* \ /usr/bin/mysql* # ホスト(自分のパソコンにあるファイル)から必要ファイルをDocker上にコピー ADD . ${HOME} # ポート3000番をあける EXPOSE 3000 # コマンドを実行 CMD ["bundle", "exec", "rails", "s", "-b", "0.0.0.0", "-p", "3000", "-e", "development"]
あなたの回答
tips
プレビュー