前提・実現したいこと
Docker for MacとRails5で開発を行っているのですが開発環境・本番環境のMySQLでエラーが出てしまい。アプリが表示されなくなりました。 デバッグにお力をおかしください。
発生している問題・エラーメッセージ
db:reset後にdb:migrateしようとしてエラー
bash
1$ docker-compose run web rails db:migrate 2Starting weinance_db_1 ... done 3Starting weinance_chrome_1 ... done 4rails aborted! 5ActiveRecord::StatementInvalid: Mysql2::Error: Tablespace is missing for table `app_name_development`.`schema_migrations`.: SHOW FULL FIELDS FROM `schema_migrations` 6/usr/local/bundle/gems/mysql2-0.5.2/lib/mysql2/client.rb:131:in `_query' 7/usr/local/bundle/gems/mysql2-0.5.2/lib/mysql2/client.rb:131:in `block in query' 8/usr/local/bundle/gems/mysql2-0.5.2/lib/mysql2/client.rb:130:in `handle_interrupt' 9/usr/local/bundle/gems/mysql2-0.5.2/lib/mysql2/client.rb:130:in `query' 10/usr/local/bundle/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:187:in `block (2 levels) in execute' 11/usr/local/bundle/gems/activesupport-5ndex.rb:92:in `register' 12 〜 (文字数制限のため中略) 〜 13/usr/local/bundle/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require' 14/usr/local/bundle/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `block in require' 15/usr/local/bundle/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in `load_dependency' 16/usr/local/bundle/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `require' 17bin/rails:4:in `<main>' 18 19Caused by: 20Mysql2::Error: Tablespace is missing for table `app_name_development`.`schema_migrations`. 21/usr/local/bundle/gems/mysql2-0.5.2/lib/mysql2/client.rb:131:in `_query' 22/usr/local/bundle/gems/mysql2-0.5.2/lib/mysql2/client.rb:131:in `block in query' 23/usr/local/bundle/gems/mysql2-0.5.2/lib/mysql2/client.rb:130:in `handle_interrupt' 24/usr/local/bundle/gems/mysql2-0.5.2/lib/mysql2/client.rb:130:in `query' 25/usr/local/bundle/gems/activerecord-`block in require' 26 〜 (文字数制限のため中略) 〜 27/usr/local/bundle/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in `load_dependency' 28/usr/local/bundle/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `require' 29bin/rails:4:in `<main>' 30Tasks: TOP => db:migrate 31(See full trace by running task with --trace)
Rootページ(localhost:3000)にアクセスしてエラー(エラー画面になって表示されない)
bash
1$docker-compose logs 2=> 3web_1 | Started GET "/" for 172.19.0.1 at 2019-09-27 16:17:10 +0000 4web_1 | Cannot render console from 172.19.0.1! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255 5web_1 | (9.7ms) SET NAMES utf8, @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483 6web_1 | ↳ /usr/local/bundle/gems/activerecord-5.2.3/lib/active_record/log_subscriber.rb:98 7web_1 | (4.0ms) SELECT `schema_migrations`.`version` FROM `schema_migrations` ORDER BY `schema_migrations`.`version` ASC 8web_1 | ↳ /usr/local/bundle/gems/activerecord-5.2.3/lib/active_record/log_subscriber.rb:98 9web_1 | 10web_1 | ActiveRecord::StatementInvalid (Mysql2::Error: Tablespace is missing for table `app_name_development`.`schema_migrations`.: SELECT `schema_migrations`.`version` FROM `schema_migrations` ORDER BY `schema_migrations`.`version` ASC): 11web_1 | 12web_1 | mysql2 (0.5.2) lib/mysql2/client.rb:131:in `_query' 13web_1 | mysql2 (0.5.2) lib/mysql2/client.rb:131:in `block in query' 14web_1 | mysql2 (0.5.2) lib/mysql2/client.rb:130:in `handle_interrupt' 15web_1 | mysql2 (0.5.2) lib/mysql2/client.rb:130:in `query' 16web_1 | activerecord (5.2.3) lib/active_record/connection_adapters/abstract_mysql_adapter.rb:187:in `block (2 levels) in execute' 17web_1 | activesupport (5.2.3) lib/active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads' 18web_1 | activesupport (5.2.3) lib/active_support/concurrency/share_lock.rb:187:in `yield_shares' 19web_1 | activesupport (5.2.3) lib/active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads' 20web_1 | activerecord (5.2.3) lib/active_record/connection_adapters/abstract_mysql_adapter.rb:186:in `block in execute' 21web_1 | activerecord (5.2.3) lib/active_record/connection_adapters/abstract_adapter.rb:581:in `block (2 levels) in log' 22web_1 | /usr/local/lib/ruby/2.6.0/monitor.rb:230:in `mon_synchronize' 23web_1 | activerecord (5.2.3) lib/active_record/connection_adapters/abstract_adapter.rb:580:in `block in log' 24web_1 | activesupport (5.2.3) lib/active_support/notifications/instrumenter.rb:23:in `instrument' 25web_1 | activerecord (5.2.3) lib/active_record/connection_adapters/abstract_adapter.rb:571:in `log' 26web_1 | activerecord (5.2.3) lib/active_record/connection_adapters/abstract_mysql_adapter.rb:185:in `execute' 27web_1 | activerecord (5.2.3) lib/active_record/connection_adapters/mysql/database_statements.rb:28:in `execute' 28web_1 | activerecord (5.2.3) lib/active_record/connection_adapters/abstract_mysql_adapter.rb:196:in `execute_and_free' 29web_1 | activerecord (5.2.3) lib/active_record/connection_adapters/mysql/database_statements.rb:33:in `exec_query' 30web_1 | activerecord (5.2.3) lib/active_record/connection_adapters/abstract/database_statements.rb:478:in `select' 31web_1 | activerecord (5.2.3) lib/active_record/connection_adapters/abstract/database_statements.rb:70:in `select_all' 32web_1 | activerecord (5.2.3) lib/active_record/connection_adapters/abstract/query_cache.rb:104:in `block in select_all' 33web_1 | activerecord (5.2.3) lib/active_record/connection_adapters/abstract/query_cache.rb:127:in `block in cache_sql' 34web_1 | /usr/local/lib/ruby/2.6.0/monitor.rb:230:in `mon_synchronize' 35 〜 (文字数制限のため中略) 〜 36web_1 | activesupport (5.2.3) lib/active_support/tagged_logging.rb:28:in `tagged' 37web_1 | activesupport (5.2.3) lib/active_support/tagged_logging.rb:71:in `tagged' 38web_1 | railties (5.2.3) lib/rails/rack/logger.rb:26:in `call' 39web_1 | sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call' 40web_1 | actionpack (5.2.3) lib/action_dispatch/middleware/remote_ip.rb:81:in `call' 41web_1 | actionpack (5.2.3) lib/action_dispatch/middleware/request_id.rb:27:in `call' 42web_1 | rack (2.0.7) lib/rack/method_override.rb:22:in `call' 43web_1 | rack (2.0.7) lib/rack/runtime.rb:22:in `call' 44web_1 | activesupport (5.2.3) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call' 45web_1 | actionpack (5.2.3) lib/action_dispatch/middleware/executor.rb:14:in `call' 46web_1 | actionpack (5.2.3) lib/action_dispatch/middleware/static.rb:127:in `call' 47web_1 | rack (2.0.7) lib/rack/sendfile.rb:111:in `call' 48web_1 | railties (5.2.3) lib/rails/engine.rb:524:in `call' 49web_1 | puma (3.12.1) lib/puma/configuration.rb:227:in `call' 50web_1 | puma (3.12.1) lib/puma/server.rb:660:in `handle_request' 51web_1 | puma (3.12.1) lib/puma/server.rb:474:in `process_client' 52web_1 | puma (3.12.1) lib/puma/server.rb:334:in `block in run' 53web_1 | puma (3.12.1) lib/puma/thread_pool.rb:135:in `block in spawn_thread'
該当のソースコード
なにがトリガーになってこんな状態になったかわからないため、関係がありそうなdocker-compose.ymlを示します。
yml:docker
1version: '3' 2services: 3 # mysqlのコンテナ 4 db: 5 # dbのイメージ指定。ない場合はpullする 6 image: mysql:5.7 7 # ローカル./mysqlとコンテナ/var/lib/mysqlを同期 8 volumes: 9 - ./mysql:/var/lib/mysql 10 # 環境変数を追加(MySQLのパスワードを設定) 11 environment: 12 MYSQL_ROOT_PASSWORD: password 13 MYSQL_DATABASE: root 14 ports: 15 - "3306:3306" 16 17 # Railsのコンテナ. コンテナの名前? 18 # コンテナ名なのでなんでもいい 19 web: 20 # Dockerfileがあるディレクトリ 21 build: . 22 # buildした時に実行するコマンド 23 command: /bin/sh -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'" 24 # ホスト上のディレクトリをコンテナにマウント 25 volumes: 26 - .:/app_name 27 # ポートをバインドします.ポート番号を指定. [ホスト:コンテナ]で設定 28 ports: 29 - "3000:3000" 30 # webはdbに依存。 起動順がdb→chrome→webになる。 31 depends_on: 32 - db 33 - chrome 34 35 # Headless chrome用 36 chrome: 37 image: selenium/standalone-chrome 38 ports: 39 - "4444:4444"
試したこと
- DBのリセット
- コンテナの再build
- migrate(はエラーになります)
正直いろいろ対処しているうちに悪化してしまいました。
補足情報(FW/ツールのバージョンなど)
- ruby 2.6.3
- Rails 5.2.3
- mysql2 0.5.2
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。