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

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

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

Windows 10は、マイクロソフト社がリリースしたOSです。Modern UIを標準画面にした8.1から、10では再びデスクトップ主体に戻され、UIも変更されています。PCやスマホ、タブレットなど様々なデバイスに幅広く対応していることが特徴です。

docker-compose

docker-composeとは、複数のコンテナで構成されるサービスを提供する手順を自動的し管理を簡単にするツール。composeファイルを使用しコマンド1回で設定した全サービスを作成・起動することが可能です。

Ruby on Rails

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

Q&A

0回答

947閲覧

docker-compose run web rails db:createでエラー発生

erika19

総合スコア1

Windows 10

Windows 10は、マイクロソフト社がリリースしたOSです。Modern UIを標準画面にした8.1から、10では再びデスクトップ主体に戻され、UIも変更されています。PCやスマホ、タブレットなど様々なデバイスに幅広く対応していることが特徴です。

docker-compose

docker-composeとは、複数のコンテナで構成されるサービスを提供する手順を自動的し管理を簡単にするツール。composeファイルを使用しコマンド1回で設定した全サービスを作成・起動することが可能です。

Ruby on Rails

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

0グッド

0クリップ

投稿2022/01/17 15:40

前提・実現したいこと

docher composeでRailsを構築しよう https://www.youtube.com/watch?v=ltDdZAJli8c&t=0s
上記動画にて学習中にdocker-compose run web rails db:create実施後にエラーが発生し、自己解決ができなかったため質問させていただきました。

docker-compose run web rails db:create実施後のエラーメッセージ

-docker-compose run web rails db:create実施後-

Running via Spring preloader in process 20 Unknown MySQL server host 'db' (-3) Couldn't create 'app_development' database. Please check your configuration. rake aborted! ActiveRecord::ConnectionNotEstablished: Unknown MySQL server host 'db' (-3) /usr/local/bundle/gems/activerecord-6.1.4.4/lib/active_record/connection_adapters/mysql2_adapter.rb:45:in `rescue in new_client' /usr/local/bundle/gems/activerecord-6.1.4.4/lib/active_record/connection_adapters/mysql2_adapter.rb:39:in `new_client' /usr/local/bundle/gems/activerecord-6.1.4.4/lib/active_record/connection_adapters/mysql2_adapter.rb:23:in `mysql2_connection'

docker-compose logs dbのエラーメッセージ

rails_docker-db-1 | 2022-01-17 14:45:30+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started. rails_docker-db-1 | 2022-01-17 14:45:31+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql' rails_docker-db-1 | 2022-01-17 14:45:31+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started. rails_docker-db-1 | 2022-01-17T14:45:31.470914Z 0 [Warning] [MY-010918] [Server] 'default_authentication_plugin' is deprecated and will be removed in a future release. Please use authentication_policy instead. rails_docker-db-1 | 2022-01-17T14:45:31.470939Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.27) starting as process 1 rails_docker-db-1 | 2022-01-17T14:45:31.492348Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /var/lib/mysql/ is case insensitive rails_docker-db-1 | 2022-01-17T14:45:31.512431Z 0 [Warning] [MY-000054] [Server] World-writable config file '/var/lib/mysql/auto.cnf' is ignored. rails_docker-db-1 | 2022-01-17T14:45:31.514593Z 0 [Warning] [MY-010107] [Server] World-writable config file '/var/lib/mysql/auto.cnf' has been removed. rails_docker-db-1 | 2022-01-17T14:45:31.515672Z 0 [Warning] [MY-010075] [Server] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 1eb4e382-77a4-11ec-b9a7-0242ac130002. rails_docker-db-1 | 2022-01-17T14:45:31.530706Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started. rails_docker-db-1 | 2022-01-17T14:45:32.773293Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended. rails_docker-db-1 | mysqld: Table 'mysql.plugin' doesn't exist rails_docker-db-1 | 2022-01-17T14:45:33.020417Z 0 [ERROR] [MY-010735] [Server] Could not open the mysql.plugin table. Please perform the MySQL upgrade procedure.

該当のソースコード

Dockerfile

1FROM ruby:2.7 2RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \ 3 && echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \ 4 && apt-get update -qq \ 5 && apt-get install -y nodejs yarn 6WORKDIR /app 7COPY ./src /app 8RUN bundle config --local set path 'vendor/bundle' \ 9 && bundle install

database.yml

1default: &default 2 adapter: mysql2 3 encoding: utf8mb4 4 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> 5 username: root 6 password: password 7 host: db 8 9development: 10 <<: *default 11 database: app_development 12 13test: 14 <<: *default 15 database: app_test 16 17production: 18 <<: *default 19 database: app_production 20 username: app 21 password: <%= ENV['APP_DATABASE_PASSWORD'] %> 22

Gemfile

1source 'https://rubygems.org' 2git_source(:github) { |repo| "https://github.com/#{repo}.git" } 3 4ruby '2.7.5' 5 6# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main' 7gem 'rails', '~> 6.1.4', '>= 6.1.4.4' 8# Use mysql as the database for Active Record 9gem 'mysql2', '~> 0.5' 10# Use Puma as the app server 11gem 'puma', '~> 5.0' 12# Use SCSS for stylesheets 13gem 'sass-rails', '>= 6' 14# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker 15gem 'webpacker', '~> 5.0' 16# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks 17gem 'turbolinks', '~> 5' 18# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 19gem 'jbuilder', '~> 2.7' 20# Use Redis adapter to run Action Cable in production 21# gem 'redis', '~> 4.0' 22# Use Active Model has_secure_password 23# gem 'bcrypt', '~> 3.1.7' 24 25# Use Active Storage variant 26# gem 'image_processing', '~> 1.2' 27 28# Reduces boot times through caching; required in config/boot.rb 29gem 'bootsnap', '>= 1.4.4', require: false 30 31group :development, :test do 32 # Call 'byebug' anywhere in the code to stop execution and get a debugger console 33 gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] 34end 35 36group :development do 37 # Access an interactive console on exception pages or by calling 'console' anywhere in the code. 38 gem 'web-console', '>= 4.1.0' 39 # Display performance information such as SQL time and flame graphs for each request in your browser. 40 # Can be configured to work on production as well see: https://github.com/MiniProfiler/rack-mini-profiler/blob/master/README.md 41 gem 'rack-mini-profiler', '~> 2.0' 42 gem 'listen', '~> 3.3' 43 # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring 44 gem 'spring' 45end 46 47group :test do 48 # Adds support for Capybara system testing and selenium driver 49 gem 'capybara', '>= 3.26' 50 gem 'selenium-webdriver' 51 # Easy installation and use of web drivers to run system tests with browsers 52 gem 'webdrivers' 53end 54 55# Windows does not include zoneinfo files, so bundle the tzinfo-data gem 56gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] 57

docker

1version: '3' 2services: 3 db: 4 image: mysql:8.0 5 command: --default-authentication-plugin=mysql_native_password 6 volumes: 7 - ./src/db/mysql_data:/var/lib/mysql 8 environment: 9 MYSQL_ROOT_PASSWORD: password 10 web: 11 build: . 12 command: bundle exec rails s -p 3000 -b '0.0.0.0' 13 volumes: 14 - ./src:/app 15 ports: 16 - "3000:3000" 17 depends_on: 18 - db

試したこと

エラーメッセージUnknown MySQL server host 'db' (-3)で検索をし、
過去に解決したケースをまねてみたり、エラー解決できませんでした。
また、https://teratail.com/questions/368357
こちらの記事が全く一緒のエラーで参考にしようとしたのですが、
こちらを参考にしてもうまくいきませんでした。

検索能力が低く自己解決できませんでしたので、なにか指摘点などありましたら
ご教授のほどよろしくお願いいたします。

明日明後日と徹夜仕事となりそうなのでご指摘いただいても
すぐに返信ができないかもしれませんが、必ず返信はいたしますのでよろしくお願いいたします。

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

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

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

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

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

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問