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

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

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

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

Ruby on Rails

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

データベース

データベースとは、データの集合体を指します。また、そのデータの集合体の共用を可能にするシステムの意味を含めます

Docker

Dockerは、Docker社が開発したオープンソースのコンテナー管理ソフトウェアの1つです

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

Q&A

1回答

1557閲覧

Mysql2::Error::ConnectionError: Unknown MySQL server host 'db' (2)

tomsuma

総合スコア38

MySQL

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

Ruby on Rails

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

データベース

データベースとは、データの集合体を指します。また、そのデータの集合体の共用を可能にするシステムの意味を含めます

Docker

Dockerは、Docker社が開発したオープンソースのコンテナー管理ソフトウェアの1つです

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

0グッド

0クリップ

投稿2020/09/07 13:39

編集2020/09/08 03:39

EC2内でマイグレーションファイルを贈ろうとしたところエラーが起きました、
rails s をやっても同じエラーがおきます。
ログを調べたところCould not find minitest-5.14.2 in any of the sources
とあったのでbundle update minitest したのですが治りませんでした。。

試したコマンド

bundle install
bundle update
bundle update minitest

エラー原因のminitestをgemgile.lookから消したのですが、
その他にも消かなくてはいけないパッケージがかなりあったのでやめました。

イメージ説明

イメージ説明

イメージ説明

初めのエラー [ec2-user@ip-172-31-4-209 Books]$ rails db:migrate RAILS_ENV=production DEPRECATION WARNING: Including LoggerSilence is deprecated and will be removed in Rails 6.1. Please use `ActiveSupport::LoggerSilence` instead (called from <main> at /var/www/Books/config/application.rb:7) rails aborted! Mysql2::Error::ConnectionError: Unknown MySQL server host 'db' (2) /var/www/Books/bin/rails:9:in `<top (required)>' /var/www/Books/bin/spring:15:in `<top (required)>' bin/rails:3:in `load' bin/rails:3:in `<main>' Tasks: TOP => db:migrate (See full trace by running task with --trace)
Books % docker-compose ps Name Command State Ports --------------------------------------------------------------------------------------- books_db_1 docker-entrypoint.sh --def ... Up 0.0.0.0:4306->3306/tcp, 33060/tcp books_web_1 bash -c rm -f tmp/pids/ser ... Exit 1
Books % docker-compose logs db Attaching to books_db_1 2020-09-07T10:09:59.502935Z 0 [System] [MY-013172] [Server] Received SHUTDOWN from user <via user signal>. Shutting down mysqld (Version: 8.0.21). db_1 | 2020-09-07T10:10:02.371623Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.21) MySQL Community Server - GPL. db_1 | 2020-09-07 13:12:26+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.21-1debian10 started. db_1 | 2020-09-07 13:12:26+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql' db_1 | 2020-09-07 13:12:26+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.21-1debian10 started. db_1 | 2020-09-07T13:12:26.968837Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.21) starting as process 1 db_1 | 2020-09-07T13:12:26.993639Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started. db_1 | 2020-09-07T13:12:27.422215Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended. db_1 | 2020-09-07T13:12:27.629852Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock db_1 | 2020-09-07T13:12:27.812775Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed. db_1 | 2020-09-07T13:12:27.812974Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel. db_1 | 2020-09-07T13:12:27.815671Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory. db_1 | 2020-09-07T13:12:27.859724Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.21' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
Books % docker-compose up Starting books_db_1 ... done Starting books_web_1 ... done Attaching to books_db_1, books_web_1 db_1 | 2020-09-07 13:36:52+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.21-1debian10 started. db_1 | 2020-09-07 13:36:52+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql' db_1 | 2020-09-07 13:36:52+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.21-1debian10 started. db_1 | 2020-09-07T13:36:52.786290Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.21) starting as process 1 db_1 | 2020-09-07T13:36:52.797137Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started. db_1 | 2020-09-07T13:36:53.077210Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended. web_1 | bundler: failed to load command: rails (/usr/local/bundle/bin/rails) web_1 | Bundler::GemNotFound: Could not find minitest-5.14.2 in any of the sources web_1 | /usr/local/bundle/gems/bundler-2.1.4/lib/bundler/spec_set.rb:86:in `block in materialize' web_1 | /usr/local/bundle/gems/bundler-2.1.4/lib/bundler/spec_set.rb:80:in `map!' web_1 | /usr/local/bundle/gems/bundler-2.1.4/lib/bundler/spec_set.rb:80:in `materialize' web_1 | /usr/local/bundle/gems/bundler-2.1.4/lib/bundler/definition.rb:170:in `specs' web_1 | /usr/local/bundle/gems/bundler-2.1.4/lib/bundler/definition.rb:237:in `specs_for' web_1 | /usr/local/bundle/gems/bundler-2.1.4/lib/bundler/definition.rb:226:in `requested_specs' web_1 | /usr/local/bundle/gems/bundler-2.1.4/lib/bundler/runtime.rb:101:in `block in definition_method' web_1 | /usr/local/bundle/gems/bundler-2.1.4/lib/bundler/runtime.rb:20:in `setup' web_1 | /usr/local/bundle/gems/bundler-2.1.4/lib/bundler.rb:149:in `setup' web_1 | /usr/local/bundle/gems/bundler-2.1.4/lib/bundler/setup.rb:20:in `block in <top (required)>' web_1 | /usr/local/bundle/gems/bundler-2.1.4/lib/bundler/ui/shell.rb:136:in `with_level' web_1 | /usr/local/bundle/gems/bundler-2.1.4/lib/bundler/ui/shell.rb:88:in `silence' web_1 | /usr/local/bundle/gems/bundler-2.1.4/lib/bundler/setup.rb:20:in `<top (required)>' db_1 | 2020-09-07T13:36:53.259743Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock books_web_1 exited with code 1 db_1 | 2020-09-07T13:36:53.403640Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed. db_1 | 2020-09-07T13:36:53.404316Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel. db_1 | 2020-09-07T13:36:53.408647Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory. db_1 | 2020-09-07T13:36:53.453959Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.21' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.

docker

1 docker-compose run web rails db:migrate RAILS_ENV=production 2Starting books_db_1 ... done 3Starting books_chrome_1 ... done 4Creating books_web_run ... done 5Could not find minitest-5.14.2 in any of the sources 6Run `bundle install` to install missing gems.
version: '3' services: db: image: mysql volumes: - ./tmp/db:/var/lib/mysql/data web: build: . command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'" volumes: - .:/Books ports: - "3000:3000" depends_on: - db - chrome stdin_open: true tty: true chrome: image: selenium/standalone-chrome:3.141.59-dubnium ports: - 4444:4444

dockerfile

1FROM ruby:2.6.3 2RUN apt-get update -qq && apt-get install -y nodejs postgresql-client yarn chromium-driver # yarnとchromium-driverを追記 3RUN mkdir /Books 4WORKDIR /Books 5COPY Gemfile /Books/Gemfile 6COPY Gemfile.lock /Books/Gemfile.lock 7RUN gem install bundler 8RUN bundle install 9COPY . /Books 10COPY entrypoint.sh /usr/bin/ 11RUN chmod +x /usr/bin/entrypoint.sh 12ENTRYPOINT ["entrypoint.sh"] 13EXPOSE 3000 14CMD ["rails", "server", "-b", "0.0.0.0"]

database.yml

1 2default: &default 3 adapter: mysql2 4 encoding: utf8 5 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> 6 username: root 7 password: example 8 # socket: /tmp/mysql.sock 9 10 host: db 11 12development: 13 <<: *default 14 database: Books_development 15 16test: 17 <<: *default 18 database: Books_test 19 20production: 21 <<: *default 22 database: Books_production 23 24 username: root 25 password: <%= ENV['DATABASE_PASSWORD'] %> 26 # socket: /var/lib/mysql/mysql.sock

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

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

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

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

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

guest

回答1

0

[ec2-user@ip-172-31-4-209 Books]$ rails db:migrate RAILS_ENV=production

このコマンドは、webコンテナで実行するコマンドではないでしょうか?
ホストは、db という名前でdbコンテナを参照できませんので…

投稿2020/09/07 14:27

YakumoSaki

総合スコア2027

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

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

tomsuma

2020/09/07 21:14

ご回答ありがとうございます! 今回はじめて使う初心者なため、全くコマンドについて詳しくありません、 大変お手数ですが、なにか参考となる資料などあればご教授お願いします!
YakumoSaki

2020/09/08 00:48

環境がわからないので推測ですが、 DBコンテナが起動している状態で docker-compose run web rails db:migrate RAILS_ENV=production で、動くと思います
tomsuma

2020/09/08 01:49

お返事ありがとうございます。 同じエラーが検出されました。 詳細を追記させてもらいました
YakumoSaki

2020/09/08 02:14

もしかしてなんですが docker-compose run web bundle install って実行すると直ったりしませんか?
tomsuma

2020/09/08 03:32

一度、お、これはいけたか! という反応を見せたのでスが、やはりだめでした、、、
tomsuma

2020/09/08 03:39 編集

一度Dockerの方を削除します
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

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

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

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

ただいまの回答率
85.46%

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

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

質問する

関連した質問