前提・実現したいこと
DockerでRailsのローカルサーバーを立ち上げることを目的にDockerを用いて環境を構築しているのですが、最後の段階の$ docker-compose run web rake db:create
を実行し、ブラウザ上で動作が確認できることを表すお馴染みの楽しそうなイラストの画面を表示させたかったのですが最後のエラーにつまずきエラーが発生しています。ご教授頂けましたら幸いです。
発生している問題・エラーメッセージ
エラーの内容を説明致します。ローカルホストで立ち上げようとするとこちらのエラーが発生します。
調べたところパスワードの未設定が原因だということがわかりました。なので下記のようにdatebase.yml
にパスワードを設定しました。
default: &default adapter: postgresql encoding: unicode host: db username: postgres password: postgres ←パスワードの設定をしました pool: 5 development: <<: *default database: myapp_development test: <<: *default database: myapp_test
そしてその後にきちんとdocker-compose run web bundle exec rake db:migrate
を実行してからサイド立ち上げようとしても同じ当初のエラーから変わりませんでした...エラー内容が変わらないということは変更が反映されていないんだ。ということはわかっているので再度$ docker-compose run web rake db:create
を試してみたり、あるいは他のパスワードに変更してみたりとして変化を確かめましたがパスワード設定前とエラー内容が変わらないという不思議な状態に頭を抱えています。
ちなみにターミナル上の記述は以下になります。
パスワードを変更したあとにdocker-compose run web bundle exec rake db:migrate
を実行
ChisakinoMacBook-Pro:docker_sample Chisaki$ docker-compose run web bundle exec rake db:migrate Starting docker_sample_db_1 ... done rake aborted! PG::ConnectionBad: FATAL: password authentication failed for user "postgres" /usr/local/bundle/gems/pg-1.2.3/lib/pg.rb:58:in `initialize' /usr/local/bundle/gems/pg-1.2.3/lib/pg.rb:58:in `new' /usr/local/bundle/gems/pg-1.2.3/lib/pg.rb:58:in `connect' /usr/local/bundle/gems/activerecord-5.2.4.2/lib/active_record/connection_adapters/postgresql_adapter.rb:692:in `connect' /usr/local/bundle/gems/activerecord-5.2.4.2/lib/active_record/connection_adapters/postgresql_adapter.rb:223:in `initialize' /usr/local/bundle/gems/activerecord-5.2.4.2/lib/active_record/connection_adapters/postgresql_adapter.rb:48:in `new' /usr/local/bundle/gems/activerecord-5.2.4.2/lib/active_record/connection_adapters/postgresql_adapter.rb:48:in `postgresql_connection' /usr/local/bundle/gems/activerecord-5.2.4.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:830:in `new_connection' /usr/local/bundle/gems/activerecord-5.2.4.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:874:in `checkout_new_connection' /usr/local/bundle/gems/activerecord-5.2.4.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:853:in `try_to_checkout_new_connection' /usr/local/bundle/gems/activerecord-5.2.4.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:814:in `acquire_connection' /usr/local/bundle/gems/activerecord-5.2.4.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:538:in `checkout' /usr/local/bundle/gems/activerecord-5.2.4.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:382:in `connection' /usr/local/bundle/gems/activerecord-5.2.4.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:1033:in `retrieve_connection' /usr/local/bundle/gems/activerecord-5.2.4.2/lib/active_record/connection_handling.rb:118:in `retrieve_connection' /usr/local/bundle/gems/activerecord-5.2.4.2/lib/active_record/connection_handling.rb:90:in `connection' /usr/local/bundle/gems/activerecord-5.2.4.2/lib/active_record/tasks/database_tasks.rb:172:in `migrate' /usr/local/bundle/gems/activerecord-5.2.4.2/lib/active_record/railties/databases.rake:60:in `block (2 levels) in <top (required)>' /usr/local/bundle/gems/rake-13.0.1/exe/rake:27:in `<top (required)>' /usr/local/bin/bundle:30:in `block in <main>' /usr/local/bin/bundle:22:in `<main>' Tasks: TOP => db:migrate (See full trace by running task with --trace)
DB作成時docker-compose run web rake db:create
の実行
ChisakinoMacBook-Pro:docker_sample Chisaki$ docker-compose run web rake db:create Starting docker_sample_db_1 ... done FATAL: password authentication failed for user "postgres" Couldn't create 'myapp_development' database. Please check your configuration. rake aborted! PG::ConnectionBad: FATAL: password authentication failed for user "postgres" /usr/local/bundle/gems/pg-1.2.3/lib/pg.rb:58:in `initialize' /usr/local/bundle/gems/pg-1.2.3/lib/pg.rb:58:in `new' /usr/local/bundle/gems/pg-1.2.3/lib/pg.rb:58:in `connect' /usr/local/bundle/gems/activerecord-5.2.4.2/lib/active_record/connection_adapters/postgresql_adapter.rb:692:in `connect' /usr/local/bundle/gems/activerecord-5.2.4.2/lib/active_record/connection_adapters/postgresql_adapter.rb:223:in `initialize' /usr/local/bundle/gems/activerecord-5.2.4.2/lib/active_record/connection_adapters/postgresql_adapter.rb:48:in `new' /usr/local/bundle/gems/activerecord-5.2.4.2/lib/active_record/connection_adapters/postgresql_adapter.rb:48:in `postgresql_connection' /usr/local/bundle/gems/activerecord-5.2.4.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:830:in `new_connection' /usr/local/bundle/gems/activerecord-5.2.4.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:874:in `checkout_new_connection' /usr/local/bundle/gems/activerecord-5.2.4.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:853:in `try_to_checkout_new_connection' /usr/local/bundle/gems/activerecord-5.2.4.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:814:in `acquire_connection' /usr/local/bundle/gems/activerecord-5.2.4.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:538:in `checkout' /usr/local/bundle/gems/activerecord-5.2.4.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:382:in `connection' /usr/local/bundle/gems/activerecord-5.2.4.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:1033:in `retrieve_connection' /usr/local/bundle/gems/activerecord-5.2.4.2/lib/active_record/connection_handling.rb:118:in `retrieve_connection' /usr/local/bundle/gems/activerecord-5.2.4.2/lib/active_record/connection_handling.rb:90:in `connection' /usr/local/bundle/gems/activerecord-5.2.4.2/lib/active_record/tasks/postgresql_database_tasks.rb:12:in `connection' /usr/local/bundle/gems/activerecord-5.2.4.2/lib/active_record/tasks/postgresql_database_tasks.rb:21:in `create' /usr/local/bundle/gems/activerecord-5.2.4.2/lib/active_record/tasks/database_tasks.rb:119:in `create' /usr/local/bundle/gems/activerecord-5.2.4.2/lib/active_record/tasks/database_tasks.rb:139:in `block in create_current' /usr/local/bundle/gems/activerecord-5.2.4.2/lib/active_record/tasks/database_tasks.rb:316:in `block in each_current_configuration' /usr/local/bundle/gems/activerecord-5.2.4.2/lib/active_record/tasks/database_tasks.rb:313:in `each' /usr/local/bundle/gems/activerecord-5.2.4.2/lib/active_record/tasks/database_tasks.rb:313:in `each_current_configuration' /usr/local/bundle/gems/activerecord-5.2.4.2/lib/active_record/tasks/database_tasks.rb:138:in `create_current' /usr/local/bundle/gems/activerecord-5.2.4.2/lib/active_record/railties/databases.rake:29:in `block (2 levels) in <top (required)>' /usr/local/bundle/gems/rake-13.0.1/exe/rake:27:in `<top (required)>' Tasks: TOP => db:create (See full trace by running task with --trace) ChisakinoMacBook-Pro:docker_sample Chisaki$
ちなみにパスワードの設定はpostgresという単語とpasswordの2つを試したのでそれがターミナル上の記述に反映されているかもしれませんのでお含みおき下さい。
補足情報(FW/ツールのバージョンなど)
docker 19.03.8
MacOS
あなたの回答
tips
プレビュー