質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
MySQL

MySQL(マイエスキューエル)は、TCX DataKonsultAB社などが開発するRDBMS(リレーショナルデータベースの管理システム)です。世界で最も人気の高いシステムで、オープンソースで開発されています。MySQLデータベースサーバは、高速性と信頼性があり、Linux、UNIX、Windowsなどの複数のプラットフォームで動作することができます。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

解決済

1回答

754閲覧

Mysql2::Error::ConnectionError Unknown MySQL server host 'db' (0) ←これを解決したい

unchan_net

総合スコア3

MySQL

MySQL(マイエスキューエル)は、TCX DataKonsultAB社などが開発するRDBMS(リレーショナルデータベースの管理システム)です。世界で最も人気の高いシステムで、オープンソースで開発されています。MySQLデータベースサーバは、高速性と信頼性があり、Linux、UNIX、Windowsなどの複数のプラットフォームで動作することができます。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2020/07/31 13:24

どうしてもわからないので質問させてください。

エラーコードを検索して、一通り試してみたのですが、原因特定には至らず。

流れとしては、 docker(rails) の環境構築は成功して、一度 rails s をした時は、しっかりと表示されました。

変更点と致しましては、次の日に、 rails generate controller StaticPages home help を実行し、新しくコントローラーを作成した時に、 bundle のバージョンが違うとのエラーがでて、 gemfile.lock を少し触ったくらいです。

この変更をした後に、rails s したところでエラーに気がつきました。

ターミナル1

docker

1Starting nouhin_app_db_1 ... done 2Starting nouhin_app_web_1 ... done 3Attaching to nouhin_app_db_1, nouhin_app_web_1 4db_1 | 2020-07-31 12:46:40+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.31-1debian10 started. 5db_1 | 2020-07-31 12:46:40+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql' 6db_1 | 2020-07-31 12:46:40+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.31-1debian10 started. 7db_1 | 2020-07-31T12:46:40.998604Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 8db_1 | 2020-07-31T12:46:40.999970Z 0 [Note] mysqld (mysqld 5.7.31) starting as process 1 ... 9db_1 | 2020-07-31T12:46:41.003157Z 0 [Note] InnoDB: PUNCH HOLE support available 10db_1 | 2020-07-31T12:46:41.003213Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 11db_1 | 2020-07-31T12:46:41.003233Z 0 [Note] InnoDB: Uses event mutexes 12db_1 | 2020-07-31T12:46:41.003243Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier 13db_1 | 2020-07-31T12:46:41.003251Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11 14db_1 | 2020-07-31T12:46:41.003259Z 0 [Note] InnoDB: Using Linux native AIO 15db_1 | 2020-07-31T12:46:41.003598Z 0 [Note] InnoDB: Number of pools: 1 16db_1 | 2020-07-31T12:46:41.003765Z 0 [Note] InnoDB: Using CPU crc32 instructions 17db_1 | 2020-07-31T12:46:41.006064Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M 18db_1 | 2020-07-31T12:46:41.015164Z 0 [Note] InnoDB: Completed initialization of buffer pool 19db_1 | 2020-07-31T12:46:41.018020Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority(). 20db_1 | 2020-07-31T12:46:41.030979Z 0 [Note] InnoDB: Highest supported file format is Barracuda. 21db_1 | 2020-07-31T12:46:41.042335Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables 22db_1 | 2020-07-31T12:46:41.042427Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ... 23db_1 | 2020-07-31T12:46:41.057836Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB. 24db_1 | 2020-07-31T12:46:41.058785Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active. 25db_1 | 2020-07-31T12:46:41.058821Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active. 26db_1 | 2020-07-31T12:46:41.059273Z 0 [Note] InnoDB: Waiting for purge to start 27db_1 | 2020-07-31T12:46:41.109709Z 0 [Note] InnoDB: 5.7.31 started; log sequence number 12578102 28db_1 | 2020-07-31T12:46:41.110122Z 0 [Note] Plugin 'FEDERATED' is disabled. 29db_1 | 2020-07-31T12:46:41.110559Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool 30db_1 | 2020-07-31T12:46:41.114371Z 0 [Note] InnoDB: Buffer pool(s) load completed at 200731 12:46:41 31db_1 | 2020-07-31T12:46:41.117648Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them. 32db_1 | 2020-07-31T12:46:41.117693Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory. 33db_1 | 2020-07-31T12:46:41.118446Z 0 [Warning] CA certificate ca.pem is self signed. 34db_1 | 2020-07-31T12:46:41.118496Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory. 35db_1 | 2020-07-31T12:46:41.118975Z 0 [Note] Server hostname (bind-address): '*'; port: 3306 36db_1 | 2020-07-31T12:46:41.119178Z 0 [Note] IPv6 is available. 37db_1 | 2020-07-31T12:46:41.119212Z 0 [Note] - '::' resolves to '::'; 38db_1 | 2020-07-31T12:46:41.119234Z 0 [Note] Server socket created on IP: '::'. 39db_1 | 2020-07-31T12:46:41.120790Z 0 [Warning] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory. 40db_1 | 2020-07-31T12:46:41.134861Z 0 [Note] Event Scheduler: Loaded 0 events 41db_1 | 2020-07-31T12:46:41.135772Z 0 [Note] mysqld: ready for connections. 42db_1 | Version: '5.7.31' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server (GPL) 43web_1 | /usr/local/lib/ruby/site_ruby/2.5.0/bundler/lockfile_parser.rb:108:in `warn_for_outdated_bundler_version': You must use Bundler 2 or greater with this lockfile. (Bundler::LockfileError) 44web_1 | from /usr/local/lib/ruby/site_ruby/2.5.0/bundler/lockfile_parser.rb:95:in `initialize' 45web_1 | from /usr/local/lib/ruby/site_ruby/2.5.0/bundler/definition.rb:83:in `new' 46web_1 | from /usr/local/lib/ruby/site_ruby/2.5.0/bundler/definition.rb:83:in `initialize' 47web_1 | from /usr/local/lib/ruby/site_ruby/2.5.0/bundler/dsl.rb:234:in `new' 48web_1 | from /usr/local/lib/ruby/site_ruby/2.5.0/bundler/dsl.rb:234:in `to_definition' 49web_1 | from /usr/local/lib/ruby/site_ruby/2.5.0/bundler/dsl.rb:13:in `evaluate' 50web_1 | from /usr/local/lib/ruby/site_ruby/2.5.0/bundler/definition.rb:34:in `build' 51web_1 | from /usr/local/lib/ruby/site_ruby/2.5.0/bundler.rb:135:in `definition' 52web_1 | from /usr/local/lib/ruby/site_ruby/2.5.0/bundler.rb:101:in `setup' 53web_1 | from /usr/local/lib/ruby/site_ruby/2.5.0/bundler/setup.rb:20:in `<top (required)>' 54web_1 | from /usr/local/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:130:in `require' 55web_1 | from /usr/local/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:130:in `rescue in require' 56web_1 | from /usr/local/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:34:in `require' 57web_1 | from /app_name/config/boot.rb:3:in `<top (required)>' 58web_1 | from bin/rails:3:in `require_relative' 59web_1 | from bin/rails:3:in `<main>' 60nouhin_app_web_1 exited with code 1 61

ターミナル2

rails

1=> Booting Puma 2=> Rails 5.2.4.3 application starting in development 3=> Run `rails server -h` for more startup options 4Puma starting in single mode... 5* Version 3.12.6 (ruby 2.5.3-p105), codename: Llamas in Pajamas 6* Min threads: 5, max threads: 5 7* Environment: development 8* Listening on tcp://localhost:3000 9Use Ctrl-C to stop 10Started GET "/" for ::1 at 2020-07-31 21:47:13 +0900 11 12Mysql2::Error::ConnectionError (Unknown MySQL server host 'db' (0)): 13

database.yml

# # Install the MySQL driver # gem install mysql2 # # Ensure the MySQL gem is defined in your Gemfile # gem 'mysql2' # # And be sure to use new-style password hashing: # https://dev.mysql.com/doc/refman/5.7/en/password-hashing.html # default: &default adapter: mysql2 encoding: utf8 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> username: root password: password host: db development: <<: *default database: app_name_development # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: <<: *default database: app_name_test # As with config/secrets.yml, you never want to store sensitive information, # like your database password, in your source code. If your source code is # ever seen by anyone, they now have access to your database. # # Instead, provide the password as a unix environment variable when you boot # the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database # for a full rundown on how to provide these environment variables in a # production deployment. # # On Heroku and other platform providers, you may have a full connection URL # available as an environment variable. For example: # # DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase" # # You can use this database configuration with: # # production: # url: <%= ENV['DATABASE_URL'] %> # production: <<: *default database: app_name_production username: app_name password: <%= ENV['APP_NAME_DATABASE_PASSWORD'] %>

docker-compose.yml

version:

1services: 2 db: 3 image: mysql:5.7 4 environment: 5 MYSQL_ROOT_PASSWORD: password 6 MYSQL_DATABASE: root 7 ports: 8 - "3306:3306" 9 10 web: 11 build: . 12 command: rails s -p 3000 -b '0.0.0.0' 13 volumes: 14 - .:/app_name 15 ports: 16 - "3000:3000" 17 links: 18 - db

長々と失礼致しました。

些細なことでもヒントを頂けると、嬉しいです

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

console

1web_1 | /usr/local/lib/ruby/site_ruby/2.5.0/bundler/lockfile_parser.rb:108:in `warn_for_outdated_bundler_version': You must use Bundler 2 or greater with this lockfile. (Bundler::LockfileError)

上記の箇所がエラーの原因のように見えます

次のようにすると良いようです
You must use Bundler 2 or greater with this lockfile. (Bundler::LockfileError) · Issue #7463 · jekyll/jekyll

update Rubygems
gem update --system

update bundler
gem install bundler

update Gemfile.lock in your project
bundler update --bundler

しかし、docker-compose.yml からすると、Dockerfile を使っていると思いますので
次のようにする必要がありそうです:

1
gem update --system, gem install bundler
Dockerfile の中で RUN 命令で指定します

2
手順 1 で編集した Dockerfile からイメージを再ビルドします

3
手順 2 で再ビルドしたイメージからコンテナーを起動し、
コンテナー内で bundler update を実行します

4
手順 3 で更新された Gemfile.lock を使って
イメージを再々ビルドし直します

投稿2020/07/31 15:10

y_shinoda

総合スコア3272

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問